re-arranging text in a file with AWK

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers re-arranging text in a file with AWK
# 1  
Old 02-12-2008
Data re-arranging text in a file with AWK

Hi Gurus,

I have a text file that I want to process with the following structure;

4528788 Blah - Something
9341423 Text - Somethinghere
98792223,5546761 Some - More - Text
5119503,5159504,1234567 Text - More - Text
13459695 Stuff - Text Again
13526583 Junk - More Text Here
13595177 T.E.X.T - Here

And I want to reformat so it looks like this;

4528788,Blah - Something
9341423,Text - Somethinghere
98792223,Some - More - Text
5546761,Some - More - Text
5119503,Text - More - Text
5159504,Text - More - Text
1234567,Text - More - Text
13459695,Stuff - Text Again
13526583,Junk - More Text Here
13595177,T.E.X.T - Here

Any Ideas? Should I be using sed instead?!

# 2  
Old 02-12-2008
awk 'c=split($1,x,","){for(i=1;i<=c;i++){$1=x[i]",";print}}' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Splitting a text file into smaller files with awk, how to create a different name for each new file

Hello, I have some large text files that look like, putrescine Mrv1583 01041713302D 6 5 0 0 0 0 999 V2000 2.0928 -0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 5.6650 0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.5217 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

3. Shell Programming and Scripting

Sorting/Arranging file based on tags using awk

Hi, I have file which contains data based on tags. Output of the file should be in order of tags. Below are the files : Tags.txt f12 f13 f23 f45 f56 Original data is like this : Data.txt 2017/01/04|09:07:00:021|R|XYZ|38|9|1234|f12=CAT|f23=APPLE|f45=PENCIL|f13=CAR... (5 Replies)
Discussion started by: Prathmesh
5 Replies

4. UNIX for Beginners Questions & Answers

Help arranging text

By using this code how can we get the stars in inverted positions? str="*" for i in 1 2 3 4 5 do echo "$str" str="$str *" done The output should be like this * * * * * * * * * * * * * * * Please use CODE tags as required by forum rules!... (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies

5. Shell Programming and Scripting

Awk to convert a text file to CSV file with some string manipulation

Hi , I have a simple text file with contents as below: 12345678900 971,76 4234560890 22345678900 5971,72 5234560990 32345678900 71,12 6234560190 the new csv-file should be like: Column1;Column2;Column3;Column4;Column5 123456;78900;971,76;423456;0890... (9 Replies)
Discussion started by: FreddyDaKing
9 Replies

6. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

7. Shell Programming and Scripting

arranging columns with AWK

Hi there! Can this be done with AWK? Several text files (file1, file2, etc) with different number of lines. Need to append each file to a Reference File (ReFile), and match each line of file1, file2 etc to the closest value in ReFile. Empty cells must be filled with NA, or 0. The number of lines... (2 Replies)
Discussion started by: sramirez
2 Replies

8. Shell Programming and Scripting

arranging datas if input file is not having also...!!

hi, my input file is containg uid, eriMaster ,eriResign, ericontry, dept. some of the uid are not having all info. out put should include all info irrespctive of datas of input file if any one data is missing, then it has to print Null or zero..then continue with the existing one. here... (0 Replies)
Discussion started by: hegdeshashi
0 Replies

9. UNIX for Dummies Questions & Answers

Re-arranging lines of text... help?

Hello, I am new to Linux, and I am learning slowly but for surely. I am trying to currently figure out how to go about re-arranging lines of text of a *.txt file... Like for example: Say pool.txt has 20 lines of text, and the last 5 lines of text I want to move to the top of the *.txt file... (2 Replies)
Discussion started by: shorte85
2 Replies

10. Shell Programming and Scripting

Help with arranging data file

Dears, I have the below data, sss-aaaaaa 111211 222222 33333 22222 1163111 sss-vvvvvv 111311 224522 335633 24322 111511 sss-cccccc 111221 224522 333333 24322 111511 sss-dddddd 111211 222222 33333 22345222 113111 I want to make them like ... (7 Replies)
Discussion started by: yahyaaa
7 Replies
Login or Register to Ask a Question