swap fields in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers swap fields in a file
# 1  
Old 10-30-2008
swap fields in a file

I have a file (tmp.out) with contents delimited by '|':

1|d|2|rt|
3|sfd|4|sgf|
5|sg|6|gtr|
7|s|8|sf|

I want to write only the 1st and 3rd columns to another file, but they should be swapped with each other:

2|1
4|3
6|5
8|7

Here is what I have so far:

cat tmp.out | cut -d'|' -f3,1 > eid_tmp.out

Thanks,

- CB
# 2  
Old 10-30-2008
Code:
awk -F'|' '{print $3, $1 }' oldfile > newfile

The -F option specifies the field separator, $1 is field one, $3 is field three.
# 3  
Old 10-30-2008
sweet... it works.

Thanks,

- CB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Explain the output of swap -s and swap -l

Hi Solaris Folks :), I need to calculate the swap usage on solaris server, please let me understand the output of below swap -s and swap -l commands. $swap -s total: 1774912k bytes allocated + 240616k reserved = 2015528k used, 14542512k available $swap -l swapfile dev swaplo... (6 Replies)
Discussion started by: seenuvasan1985
6 Replies

2. Shell Programming and Scripting

Swap of fields dynamically

Dear Friends, I have file a.txt 1|2|3|4|5|6|7|8 a|b|c|d|e|f|g|h i am using the below code to swap the fields in file awk -F\| '{print $5,$1,$2,$3,$4,$6,$7,$8}' OFS=\| a.txt > output.txt output.txt 5|1|2|3|4|6|7|8 e|a|b|c|d|f|g|h The above command is working fine. I am... (4 Replies)
Discussion started by: i150371485
4 Replies

3. UNIX for Dummies Questions & Answers

vi editor swap file please help

Hi, when using vi editor, why do i automatically create swap file. this is very hard on me as on some systems i do not have remove file permission and swap file is only readable. it always happens to me, regardless of the computer i am using. does not happen to my classmates. i don't even know the... (2 Replies)
Discussion started by: hobiwhenuknowme
2 Replies

4. UNIX for Dummies Questions & Answers

How to swap parts of a file name?

I have a number of files that a structured like this: Eg. file_name.ext1 another file name with spaces.ext2 yatf with .ext3 also a file (plus).ext4 I would like to swap the part with the descriptive_file_name part, so that it looks like this: Eg. file_name .ext1 I know (or... (4 Replies)
Discussion started by: invenio
4 Replies

5. HP-UX

Swap device file and swap sapce

Hi I have an integrity machine rx7620 and rx8640 running hp-ux 11.31. I'm planning to fine tune the system: - I would like to know when does the memory swap space spill over to the device swap space? - And how much % of memory swap utilization should be specified (swap space device... (6 Replies)
Discussion started by: lamoul
6 Replies

6. UNIX for Advanced & Expert Users

Swap file system

This questions only concerns Solaris 10. Let's say I have swap configured like so in /etc/vfstab: /dev/dsk/c1t0d0s1 - - swap - no - /dev/dsk/c1t1d0s1 - - swap - no - /dev/md/dsk/d1 - - swap - no - ... (1 Reply)
Discussion started by: bluescreen
1 Replies

7. Solaris

Swap config - Mirror swap or not?

Hello and thanks in advance. I have a Sun box with raid 1 on the O/S disks using solaris svm. I want to unmirror my swap partition, and add the slice on the second disk as an additional swap device. This would give me twice as much swap space. I have been warned not to do this by some... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

8. Solaris

swap file not present

Hello all, We are running a 2 gig Solaris10 system. The only application that's running on the system is ours which allocates 850MB through malloc at one shot. For some reason this malloc keeps failing saying "Resource Temporarily Unavilable" After some investigation, found that it goes... (7 Replies)
Discussion started by: Naanu
7 Replies

9. UNIX for Dummies Questions & Answers

File name swap

I'm trying to write a shell script that accepts two file extensions as command line arguments and renames all files with the first extension within the current working directory to have the second extension instead. The script should print out error messages as is appropriate if there is any... (1 Reply)
Discussion started by: asianmike
1 Replies

10. UNIX for Dummies Questions & Answers

Swap file

I just started working with AIX and need a little help. Is there a command to find the size of the swap file. (1 Reply)
Discussion started by: paule
1 Replies
Login or Register to Ask a Question