Extracting 3rd column using awk from file with spaces.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting 3rd column using awk from file with spaces.
# 1  
Old 03-25-2010
Extracting 3rd column using awk from file with spaces.

BAQ001 /dev/rdsk/c2t0d7 1C13 (M) RW 69053

The line above is from a text file. I want to use awk to extract the value in the third column 1C13.

I just can't seem to get the syntax right or something. Any help would be appreciated.

Thanks,
# 2  
Old 03-25-2010
Code:
awk '{ print $3 }' yourfile.txt

# 3  
Old 03-25-2010
Code:
 echo "BAQ001 /dev/rdsk/c2t0d7 1C13 (M) RW 69053" | sed 's/^.[^ \t]* *[^ \t]* //;s/ .*//'

# 4  
Old 03-26-2010
Just one more task using sed/awk & whatever else

Very cool. No I have two files called "std" and "vdev"

here is a sample of the values in file "std"

1C13
1C1B
1C23
1C2B
1C33
1C3B
1C43
1C4B
1C53
1C5B
1C63

Here is a sample of vale in file "vdev"

26BF
26C7
26CF
26D7
26DF
26E7
26EF
26F7
26FF
2707
270F


The first and second list correspond to each other, e.g. 1st list has the value 1C13, and the second list has a value of 26BF. They need to be combined as follows:

1C13 26BF

And then another repeating value has to be in front of each line.

example

000190102326:1C13 26BF

Any suggestions would be greatly appreciated.
# 5  
Old 03-26-2010
Hello, ricnetman:

You can join corresponding lines in std and vdev with the paste command:
Code:
paste -d' ' std vdev

If the repeating value is always the same, it can be prepended to each line with:
Code:
paste -d' ' std vdev | sed 's/^/000190102326:/'

In case there are more related questions to follow, why don't you try to give us a big picture view of what's going on? I say that because it seems that you are asking for help with each little step; if we knew more we might be able to not only provide you with better help for those steps, but perhaps even suggest a better approach in general.

Regards,
Alister

Last edited by alister; 03-26-2010 at 12:12 PM..
# 6  
Old 03-26-2010
Thanks Aliister;

The last answer put everything together for me.

In our environment, we used symetrix disk arrays. And we use an EMC NetWorker module for performing snapshot backups.

In addition to having the correct modules in place, a "symm.res" file AKA a "sets" file needs to be generated that has the serial number of the symm e.g. 000190102326, and a standard device and a virtual device e.g. 1C13 26BF.

There are three types of clones used on symms BCVs, Clones, and VDEVS.

We had already created a script for clones but did not know the correct sym commands to use to render the same results for VDEVs, and ran out of time, so I thought it would be prudent to use a combination of awk and other commands to achieve the same results until my colleague had time to modify our script script.

Thanks to all of you for the help.

ricnetman
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies

2. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

5. Shell Programming and Scripting

extracting row with max column value using awk or unix

Hello, BC106081_abc_128240811_128241377 7.96301 BC106081_abc_128240811_128241377 39.322 BC106081_cde_128240811_128241377 1.98628 BC106081_def_128240811_128241377 -2.44492 BC106081_abc_128240811_128241377 69.5504 FLJ00075_xyz_14406_16765 -0.173417 ... (3 Replies)
Discussion started by: Diya123
3 Replies

6. Shell Programming and Scripting

Extracting a column from a file and merging with other file using awk

Hi All: I have following files: File 1: <header> text... text .. text .. text .. <\header> x y z ... File 2: <header> text... text .. text .. (4 Replies)
Discussion started by: mrn006
4 Replies

7. Shell Programming and Scripting

Use awk to have the fourth column with spaces

Hi Gurus, We have a ftpserver from which we do a dir command and output it to a local file. The content of the ftpfile is: 07-15-09 06:06AM 5466 ABC_123_ER19057320090714082723.ZIP 07-15-09 06:07AM 3801 ABC_123_ER19155920090714082842.ZIP 07-15-09 06:07AM ... (14 Replies)
Discussion started by: donisback
14 Replies

8. Shell Programming and Scripting

Awk multiple lines with 3rd column onto a single line?

I have a H U G E file with over 1million entries in it. Looks something like this: USER0001|DEVICE001|VAR1 USER0001|DEVICE001|VAR2 USER0001|DEVICE001|VAR3 USER0001|DEVICE001|VAR4 USER0001|DEVICE001|VAR5 USER0001|DEVICE001|VAR6 USER0001|DEVICE002|VAR1 USER0001|DEVICE002|VAR2... (4 Replies)
Discussion started by: SoMoney
4 Replies

9. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

10. Shell Programming and Scripting

Extracting a column using AWK

Hi, I've a text file like ABC,,100 A,100,200 In the above example, I have 3 columns. I want to extract the second column. I'm expecting a value like 100 i.e first record will not have any value but still it has to give me null value. second record should give 100. Can anybody... (2 Replies)
Discussion started by: ronald_brayan
2 Replies
Login or Register to Ask a Question