Find the answer to your Linux question:
Results 1 to 3 of 3
how can i copy a certain word from a text file then use this word to replace in another text file?? i tried to use something like: awk '{print "Hit ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    8

    copy &replace text

    how can i copy a certain word from a text file then use this word to replace in another text file??
    i tried to use something like:

    awk '{print "Hit the",$1,"with your",$2}' /aaa/qqqq.txt > uu.txt

    but i can't add an argument to point to the second file which i will replace in.

    please help me

  2. #2
    Linux Newbie Ziplock's Avatar
    Join Date
    Jan 2009
    Location
    Adelaide
    Posts
    169
    Can you do something like the following:

    Code:
    WORD=$(awk '{print $1}' /aaa/qqq.txt); sed -i 's/blah/${WORD}/g' uuu.txt
    If you can provide a bit more of a solid example I may be able to help more.

  3. #3
    Just Joined!
    Join Date
    Apr 2011
    Posts
    8
    It is the content of each file:
    file1.txt:


    55:00 99:00 88:00 11:00 77:00
    file2.sh: >>"a script file"



    #!/bin/sh
    at 11:11
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 22:22
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 33:33
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 44:44
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 55:55
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    and the outputfile.sh will be:




    #!/bin/sh
    at 55:00
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 99:00
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 88:00
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 11:00
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call
    at 77:00
    cp /qq/event.call /var/spool/asterisk/outgoing/
    chmod 777 /var/spool/asterisk/outgoing/event.call

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...