select a particular field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting select a particular field
# 1  
Old 10-09-2008
Java select a particular field

hi
i have a file


wwww-qqq.eee [123343333] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343331] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343332] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343333] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda
wwww-qqq.eee [123343334] ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda

from the above file i need to extract secon field [123343333] and print that line to a separate file

please help

thanks
Satya
# 2  
Old 10-09-2008
Code:
cut -f2 file >newfile

# 3  
Old 10-09-2008
awk '{print $2,NR}' "$file_name" | cut -d'[' -f2 | tr -d ']' > "$backfile"

Last edited by a2156z; 10-09-2008 at 05:07 AM..
a2156z
# 4  
Old 10-09-2008
Yeah, you could cut on [ if you want to remove the brackets. The awk is rather unnecessary, though.

Code:
cut -d'[' -f2 file | cut -d']' -f1 >newfile

# 5  
Old 10-09-2008
Or just with awk:

Code:
awk 'BEGIN{FS="\[|\]"}{print $2}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

2. Shell Programming and Scripting

Using awk to select one field

Hi, I saw your post.. I have a dought in awk command... how to get the output from a file. i need a first column in etc/passwd file in a single column (in indivijual line)... i couldn't get with this command cat /etc/passwd | awk -F ":" '{printf $1}' Kindly help This thread was created... (3 Replies)
Discussion started by: Dheepak s
3 Replies

3. Shell Programming and Scripting

How to select a particular field from a drop-down menu in a webpage using perl script?

Hi Team, I have a requirement to login into URL using username and password , then I have to select a "particular name" from drop-down menu and then Read the values user records etc.... using perl. Is it possible to do in perl script ? (OR) Can you please let me know which scripting... (1 Reply)
Discussion started by: latika
1 Replies

4. Programming

Select and group by excluding one field

Dear community, I have a very simple query (on Oracle 11g) to select 3 fields: select field1, field2, field3, count(*) from table where... group by field1, field2, field3 having count(*) > 10;Now, what I need, is exclude "field3" from the "group by" since I only need field 1 and 2 to be... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

5. Boot Loaders

Reboot and Select Proper Boot device or insert Boot media in select Boot device and press a key

Hello, I have kubuntu on my laptop and now I decided to switch to Windows 7. I made the bios settings properly (first choice is boot from cd\vd) but I see the error " reboot and select proper Boot device or insert Boot media in select Boot device and press a key " I have tried CD and... (0 Replies)
Discussion started by: rpf
0 Replies

6. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

7. Shell Programming and Scripting

How to select or make reference to, part of a field

For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)? For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
Discussion started by: akshaykr2
5 Replies

8. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

9. Shell Programming and Scripting

::select statement return value with correct field size::

Hi Everyone, I am facing a problem regarding the select from sybase, the return with the incorrect size. For example, field is NAME(20). After i selected from sybase, the result is nicky. after i assign it to another declaration variable, it will be in actual name "nicky" , what i need... (10 Replies)
Discussion started by: ryanW
10 Replies

10. Shell Programming and Scripting

select last field from a file

hi everybody i would to select the last field of a file here as you can see i select the field number 8 y=`cat sortie2 | grep "^"| grep "starting"| awk '{ print $8}'` but line can containt more or less field in never know, i just know is the last one so i wondering to know if is... (3 Replies)
Discussion started by: kykyboss
3 Replies
Login or Register to Ask a Question