Reverse Arrange File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reverse Arrange File
# 1  
Old 06-12-2007
Reverse Arrange File

I've got hundreds of lines in a file that looks like this:

Line1 CCR CCH
Line2 ICVM FBO GSC
Line3 MKF

The result should be like the one below so that I can insert them on our database.

Line1 CCR
Line1 CCH
Line2 ICVM
Line2 FBO
Line2 GSC
Line3 MKF

Thanks in advance!
# 2  
Old 06-13-2007
Code:
nawk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile

# 3  
Old 06-13-2007
do something like the following to get just the list of words

Code:
cat input-file | while read N
do
    for d in $N
    do
         echo $d
    done
done

then run the output through sort.
# 4  
Old 06-13-2007
Quote:
Originally Posted by vgersh99
Code:
nawk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile

It worked!!! I removed the "n" on the "nawk". Some users maybe confused.
Code:
awk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile

# 5  
Old 06-13-2007
nawk is the "usable" version of awk on Solaris, vgersh works on Solaris I believe. awk on Solaris is an ancient version and does play well with everyone else's awk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Arrange file by modified date

Hi, Am performing a find based on filename and result can contain multiple files being found Let's say my find command is find /Archive -f -name 12345.pdf and result of find command is /Archive/Folder A/12345.pdf /Archive/Folder B/12345.pdf please note white space in folder names I... (2 Replies)
Discussion started by: gigagigosu
2 Replies

2. Shell Programming and Scripting

Reverse Display of a file

Hi all, Just saw a "sed" format to reverse display the file contents, but am not geting its logic completely. I would appreciate if somebody can explain sed '1!G;h;$!d' < filename All I know in this is that : G will add a new line after every line except first one... (5 Replies)
Discussion started by: dextergenious
5 Replies

3. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

4. UNIX for Dummies Questions & Answers

reverse first field from the file

Hi all, I have a file named file1as 07/25 00:10 d327490 07/25 00:55 d378299 07/25 03:58 d378299 07/25 06:14 d642035 07/25 12:44 c997126 and now i want to reverse the first filed ie 07/25 as 25/07 00:10 d327490 25/07 00:55 d378299 25/07 03:58 d378299 25/07 06:14 d642035 25/07... (5 Replies)
Discussion started by: zozoo
5 Replies

5. Shell Programming and Scripting

script to arrange file in specific format

Hi All, I am new to forum, I am looking to arrange a file in specific format but unable to get the formula to do it, already googled for the same, but didnt find the answer :(. hope to get help here :o:o:o:o:o I have to files : $ cat Dev_List2 0685 0686 0687 0688 0689 068A 068B 068C... (2 Replies)
Discussion started by: prasan_Aix
2 Replies

6. Shell Programming and Scripting

how to arrange all lines in a file to a single line

Hi Gurus, I am a starter with shell script. Help me to achieve this. I have a file with lines given below. line1 line2 line3 . . etc How can I arrange the file which should look like line1,line2,line3,..,..,etc Any help on this is appreciated. (9 Replies)
Discussion started by: smv
9 Replies

7. Shell Programming and Scripting

how to reverse file

i am using AIX -ksh how can i reverse any file ,i have already try tac cmd it is not in AIX: please help me out. (3 Replies)
Discussion started by: RahulJoshi
3 Replies

8. UNIX for Advanced & Expert Users

How to reverse the contents of a file?

Hi Guys, Am new to this forum .... And also to shell scripting I need a k-shell script to reverse the contents of a file... Please come up with the solutions... With regards, Anand (10 Replies)
Discussion started by: aajan
10 Replies

9. Shell Programming and Scripting

how to arrange 3 file to one using awk...?

I have 3 file, I want to re-arrange so all data easy to read from one file only: file1 : userA 10 20 userB 30 40 userC 50 60 .... file2 : userA var1 1000 userA var2 2000 userB var2 3000 userB var3 4000 userB var4 5000 userC var1 6000 ... file3 : userA var3 7000 userA var4 8000 (9 Replies)
Discussion started by: penyu
9 Replies

10. Shell Programming and Scripting

Need to read a file in reverse

I have to extract data from a text file which is huge in size >>10GB. ie between two strings. If I do an ordinary sed it takes forever to come out. I was wondering if there was anyway to do the entire process in reverse and on finding the relevant string is there any way to break out of the... (5 Replies)
Discussion started by: scorreg
5 Replies
Login or Register to Ask a Question