Using awk and/or sed to reconstruct a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using awk and/or sed to reconstruct a file
# 1  
Old 04-05-2013
Using awk and/or sed to reconstruct a file

So I have a file in the following format

Code:
>*42
abssdfalsdfkjfuf
asdhfskdkdklllllllffl
eiffejcif
>2
dfhucujf
dhfjdkfhskskkkkk
eifjvujf
ddftttyy
yyy
>~
ojcufk
kcdheycjc
djcyfjf

and I would like it to output
Code:
abssdfalsdfkjfufasdhfskdkdklllllllffleiffejcif
dfhucujfdhfjdkfhskskkkkkeifjvujfddftttyyyyy
ojcufkkcdheycjcdjcyfjf

So I need to remove all the lines containing ">" and join all the lines between into a single line.

Thanks in advance!!
# 2  
Old 04-05-2013
One way:

Code:
awk '/^[^>]/{printf $0;next}NR!=1{print "";}' file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 04-05-2013
Another approach, this will preserve newline in the end:
Code:
awk 'END{printf "\n"}NR==1&&/>/{next}!/>/{ORS=FS}/>/{ORS=RS;$0=""}1' file

# 4  
Old 04-05-2013
FWIW, using GNU sed:
Code:
$ sed -n '${H;bk}; />/bk; H;b; :k {g; s/\n//g; /./ p; s/.//g; x; d};' file
abssdfalsdfkjfufasdhfskdkdklllllllffleiffejcif
dfhucujfdhfjdkfhskskkkkkeifjvujfddftttyyyyy
ojcufkkcdheycjcdjcyfjf

Maybe there is a better way than this with sed. I don't know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

2. AIX

Power RAID10 array reconstruct fails ?

Hello, P7 machine PCI Express x8 Planar 3Gb SAS Adapter RAID10 array(2 disks)(not AIX lvm) was configured and working, then one disk failed and IBM support replaced that. Now raid array is degraded, data is not lost. I see new disk model(same as original) serial and etc. What I did trying... (0 Replies)
Discussion started by: vilius
0 Replies

3. Shell Programming and Scripting

> dpkg-deb to Extract and Reconstruct a Multipart Archive???

Greetings! Here's one which has been bugging me for a bit ;) As might be known, LibreOffice is available to some of us Linux folk as a large set of debs. Of course, being a curious sort, I'd like to dig in and recreate the original tree which is composed of these assorted archives. So, I... (1 Reply)
Discussion started by: LinQ
1 Replies

4. UNIX for Dummies Questions & Answers

awk code to reconstruct sequence from alignment

Hi Everyone, I need some help to construct a long 'Sbjct' string from the following input using incremental order of 'Sbjct' starting number (e.g. 26325115,33716368,33769033,34869860 etc.) Different 'Sbject' string will be separated by 'NNNN's as: ... (6 Replies)
Discussion started by: Fahmida
6 Replies

5. Shell Programming and Scripting

File comparision with AWK / SED

Hi all I need to compare two separate product lists that are changed weekly. New products are added, old products are removed and prices change. I have found various Windows programs that do this function but it's not as clean as I like and just wondered if there was a simpler way with... (1 Reply)
Discussion started by: mrpugster
1 Replies

6. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

7. Shell Programming and Scripting

Sed or Awk or both to edit file

What is an efficient way to remove all lines from the input file which contain a file name? inputfile: ======================= # comment # comment # comment 5 8 10 /tmp 5 8 10 /var/run 5 8 10 /etc/vfstab 5 8 9 /var/tmp 5 8 10 /var/adm/messages... (7 Replies)
Discussion started by: Arsenalman
7 Replies

8. Shell Programming and Scripting

sed or awk to order a file

Hi - I have a file with lots of lines in that I need to order based on the number of commas! e.g the file looks something like :- cn=john,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com... (4 Replies)
Discussion started by: sniper57
4 Replies

9. Shell Programming and Scripting

awk/sed for parsing file

Hi All, I have a log file like this E Mon Oct 06 00:17:08 2008 xxx2 cm:10614 fm_pi2_svc_iptv_purchase.c:149 1:pin_deferred_act:10601:11:169:1223245028:16 pi2_op_svc_iptv_purchase error <location=PIN_ERRLOC_FM:5 class=PIN_ERRCLASS_SYSTEM_DETERMINATE:1... (10 Replies)
Discussion started by: subin_bala
10 Replies

10. Shell Programming and Scripting

Editing File using awk/sed

Hello Awk Gurus, Can anyone of you help me with the below problem. I have got a file having data in below format pmFaultyTransportBlocks ----------------------- 9842993 pmFrmNoOfDiscRachFrames ----------------------- NULL pmNoRecRandomAccSuccess -----------------------... (4 Replies)
Discussion started by: Mohammed
4 Replies
Login or Register to Ask a Question