Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
Hi guys i wanna append a sentence starting with @ to the previous line,used sed to try,but as the lines are too many..sed could not do what i wanna do,so ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25

    Trying out Awk,pls help!

    Hi guys i wanna append a sentence starting with @ to the previous line,used sed to try,but as the lines are too many..sed could not do what i wanna do,so i thought i try out awk..can anyone tell me how to do what i want with awk?

    for example:

    hey,how are u?
    @ya i am fine!!

    what i wanted:

    hey,how are u?@ya i am fine!!

    ya basically this is what i wanna..but as there is alot of lines i need to append to the previous line,can anyone suggest anything that awk can help with this requirement?thanks alot

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk 'BEGIN{RS="\n@";ORS="@"}1' file

  3. #3
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    hey thanks ghostdog74..but still got one problem..i tried out your command,it did append to the previous line,but there is a extra @ after the sentences

    like this:
    hey,how are u?@ya i am fine!!@

    can tell me how to get rid of that?thanks alot!!

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    RS means record separator. ORS means output record separarot. specifying RS="\n@" and ORS="@" means the awk will "change" every \n@ to @ in the output. The fact you have an extra @ at the back means there could be another record, something at the last line. Show your exact input file that you have.

  5. #5
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    ok here the input file i have

    @txndb@Command_History@oracle_history!> ----------------------
    !> 01-10-07 08:17:18
    !>
    !> ----------------------
    !> 01-10-07 11:01:35
    !> \
    !> ..."™.pwd
    !> ..mkdir 20071001
    !> .ftp 172.18.14.90
    !> .ls -lrt
    !> ..pwd
    !> ..cd 20071001
    !> ..ls
    !> .ftp 172.18.14.90
    !> .ls -lrt
    !> ..pwd
    !> ..cd @txo@app@enets2@monitoring
    !> ..cd @txn
    !> ..cd app
    !> .cd enets2
    !> ..cd monitoring
    !> ..ls -l
    !> ..rm aaa.txt
    !> .clear
    !> ..ls -l
    !> ..cp -p @home@oracle@20071001@* .
    !> ..ls -l
    !> ..chmod 700 *
    !> ..ls -l
    !> ..more cron*
    !> .crontab -e
    !> .more cron*
    !> .ls -l
    !> ..vi query.sh
    !> ..ls -l
    !> ..vi query.sh
    !> ..ls -l
    !> ..more query.sh
    !> ..vi batch_monitoring.sh
    !> .ls -l
    !> ..ftp 172.18.14.90
    !> .ftp 172.18.14.90
    !> .ls -l
    !> ..vi query.sh
    !> ..clear
    !> ..ls -l
    !> ..date
    !> ..@batch_monitoring.sh
    !> ..vi query.sql
    !> .ls -l
    !> ...@batch_monitoring.sh
    !> ..ls -l
    !> ..ftp 172.18.14.90
    !> .cd @home
    !> .ls
    !> .more monitor.sh
    !> ..more monitor.sh
    !> ..cd @home
    !> .ls
    !> .ls -lt
    !> .more monitor.sh
    !> ..ftp 172.18.34.160
    !> ..cd root
    !> ..ls
    !> .ls -lt
    !> .ftp 172.18.34.160
    !> ..ls -lt
    !> .ls -lt > tmp.txt
    !> .cd ..
    !> ..cd @home
    !> .ls
    !> .ls -lt
    !> .cd @txn@app
    !> ..cd enets2
    !> ..ls
    !> .cd monitoring
    !> ..ls
    !> ..@sendmail_batchclose.sh
    !> .cd @home
    !> .ls -lt
    !> .more monitor.sh
    !> ..cd @txn@app@enets2@monitoring
    !> ..ls
    !> .more sendmail_batchclose.sh
    !> ..ls
    !> .clear
    !> ..df -k
    !> ..cat batch_close_status_montoring.txt | mail -s "test"
    !> ..more sebdnmail*
    !> ..more send*
    !> .vi sendmail_bat*
    !> ..@sendmail_batchclose.sh
    !> .vi sendmail_b*
    !> .ls -l
    !> ...@sendmail_batchclose.sh
    !> .cat batch_close_status_monitoring.txt | mail -s "test"
    !> .ls -l
    !> ..crontab -e
    !> .vi @txn@app@enets2@monitoring@batch_monitoring.sh
    !> ..ls
    !> .more @etc@hosts
    !> ..clear
    !> ..df -k
    !> ..df -k | mail -s "test"
    !> .cd @txn@app@enets2@maint
    !> .ls -lt
    !> .chmod 700 *
    !> ..ls -lt
    !> .cd @
    !> .clear
    !> ..cd @txn@app@enets2@maint
    !> .ls
    !> .le -lt
    !> .ls -lt
    !> .cd ..
    !> ..ls
    !> .cd sql
    !> .ls
    !> .ls -lt
    !> .cd ..
    !> ..ls
    !> .cd config
    !> ..ls -lt
    !> .cd ..
    !> ..cd data
    !> ..ls -lt
    !> .cd ..
    !> ..ls
    !> .cd ftpScript
    !> .ls -lt
    !> .cd bk
    !> ..ls -lt
    !> .chmod 700 *
    !> ..cd ..
    !> ..cd lib
    !> .ls -lt
    !> .cd ..
    !> ..ls
    !> .ls -lt
    !> .ls config
    !> ..ls lib
    !> .ls template
    !> ..ls -lt bk
    !> ..ls -lt
    !> .ls -lt template
    !> ..ls -lt log
    !> .ls -lt
    !> .ls -lt data
    !> ..ls -lt log
    !> .ls -lt sql
    !> .cd sql
    !> .chmod 700 *
    !> ..ls -lt
    !> .cd ..
    !> ..ls -lt
    !> .cd template
    !> ..ls -lt
    !> .chmod 700 *
    !> ..ls -lt
    !> .cd ..
    !> ..ls -lt bk
    !> ..ls -lt maint
    !> .ls -lt template
    !> ..ls -lt sql
    !> ...#8.ls -t
    !> ..pwd
    !> ..ls -l
    !> ..pwd
    !> ..cd monitoring
    !> ..ls -l
    !> ..more sendmail_doub*
    !> ..clear
    !> ..ls
    !> .ls -l
    !> ..cat sendmail_doublebatch.sh


    well...i just change the delimiter to !> and it work well too..just that behind will have a additonal !>..so i was wondering if u knw hw to solve this problem,thanks alot!

  6. #6
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    try this then:
    Code:
    awk 'BEGIN{RS="\n!>";ORS="!>"}
    RT{
    gsub(/\\\n/,"")
    print
    }' "file"

  7. #7
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    hmmm..alot of errors..i also dont knw why

    errors:
    'RT{' is not recognized as an internal or external command,
    operable program or batch file.

    'gsub' is not recognized as an internal or external command,
    operable program or batch file.

  8. #8
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    ok you don't have the GNU awk version. I am using GNU awk.
    although i don't usually do this, but this may do what you want
    Code:
    awk 'BEGIN{RS="\n@";ORS="@"}1' file | sed '$d'

  9. #9
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this:

    Code:
    awk '/^@/{if(NR > 1){print x $0}{x=$0}}' file
    Regards

  10. #10
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    haha..okok..thanks alot guys..i have one more question,cos that time i tried to use sed to do this problem,that is..i wanna match a certain word perhaps like /repdb/,so i do out a sed command which i want when match /repdb/ then it will be replace by the things inside line2.txt

    this what i come up with:

    sed "/repdb/r line2.txt" histtry2.txt>histtry3.txt

    but like this way..it will get everything which have repdb inside..but what i want is /repdb/..with the / inside..anyone can help?can i use awk to do this?pls help..thanks..

Page 1 of 2 1 2 LastLast

Posting Permissions

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