LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-30-2005, 04:17 AM   #1
Ayman.mashal
LQ Newbie
 
Registered: May 2005
Posts: 21

Rep: Reputation: 15
awk and change file content


Hi all

i have text files with the below format :

VERSION--->41
AAA-203 04150 060 120 3000 99 99
0010350000 00000054 0303 0843 011454 F033 0844 011454 000000
0100000000 00000000 0000 0000 000000 0000 0000 000000 000000
3148210035 13830131 4821 0035 138302 7000 0000 084317 084408
0002160000 00000385 0303 0855 011454 F114 0913 011465 000549

i am trying to use AWK to do the following :

1- delete the VERSION--->41 Line
2- move the AAA-* line (the seconed line) to the end of each line in the file
and delete it .

i want the result to be :
0010350000 00000054 0303 0843 011454 F033 0844 011454 000000 AAA-203 04150 060 120 3000 99 99
0100000000 00000000 0000 0000 000000 0000 0000 000000 000000 AAA-203 04150 060 120 3000 99 99
3148210035 13830131 4821 0035 138302 7000 0000 084317 084408 AAA-203 04150 060 120 3000 99 99
0002160000 00000385 0303 0855 011454 F114 0913 011465 000549 AAA-203 04150 060 120 3000 99 99

thanks
 
Old 05-30-2005, 04:32 AM   #2
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
Re: awk and change file content

hi there,
Quote:
Originally posted by Ayman.mashal

i am trying to use AWK to do the following : ...
please post what you tried so far..
"sed" will be a best option for this problem..
regards
slackie1000
 
Old 06-01-2005, 08:59 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
I'd use a script that read in each line. Ignore the first and save the AAA line in a variable, then echo each line with the variable appended. Too simple to warrant the complications of sed, really. If the requirement gets more complicated then sed would definitely be the way to go, though; awk can be a bit clunky (IMO).
 
Old 06-02-2005, 01:25 AM   #4
Ayman.mashal
LQ Newbie
 
Registered: May 2005
Posts: 21

Original Poster
Rep: Reputation: 15
thanks ppl

i tried with sed and i wrote this command :

sed -e '/VERSION/d;/AAA-/{h;d};{G;s/\n//}' *.* > all_files.txt

but i think that the replacement of the \n dosnt work , its work when i open the file in windows

but in linux i see the concatenated line in a new line !
 
Old 06-02-2005, 06:03 AM   #5
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
Quote:
Originally posted by eddiebaby1023
I'd use a script that read in each line. Ignore the first and save the AAA line in a variable, then echo each line with the variable appended. Too simple to warrant the complications of sed, really. If the requirement gets more complicated then sed would definitely be the way to go, though; awk can be a bit clunky (IMO).
ok. agreed.
the task is too simple to use sed...
i will give some tips about sed anyway....
personally, i prefer to write more statements than trying complex regexp...
something in these lines... let's say that your file is called dummy...
Code:
...
anything=`sed -n "/AAA/p" dummy`
anything2=`sed -n "/VERSION/d;/AAA/d" dummy`
...
you just need to append $anything to each line of the output from $anything2...
attention if you need this thing readable in *nix and Windows env.. you have to handel EOF ...
regards
slackie1000
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM
find the same content in the file ust Linux - Newbie 5 03-23-2005 03:03 AM
Formating a file with awk tifu Programming 5 03-16-2005 11:35 PM
editing a file using awk pantera Programming 1 05-14-2004 08:40 AM
Getting awk to extract scripts from a file jspaceman Programming 5 11-24-2002 06:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration