get lines with multiple values at a position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get lines with multiple values at a position
# 1  
Old 03-26-2008
Bug get lines with multiple values at a position

Hi,

I have a file like below:


ABC,1001,DEFG,40000
AVD,2002,FGRG,3000
DBF,2002,HDGD,3454
GDF,4564,GRTR,5656
GDF,4659,GGTD,10002
....
.....


I have to get all the lines which contains 2002 and 4659 at the second position. Please help.

The output file will be like:

AVD,2002,FGRG,3000
DBF,2002,HDGD,3454
GDF,4659,GGTD,10002


Many Thanks,
D
# 2  
Old 03-26-2008
Code:
egrep '^[^,]*,(2002|4659),' file

# 3  
Old 03-26-2008
Or:
Code:
awk '$2==4659||$2==2002' FS=',' file

# 4  
Old 03-26-2008
awk -F, '$2=="2002" || $2=="4659" ' file
# 5  
Old 03-26-2008
Or:

Code:
awk '$2~/^(2002|4659)$/' FS=, file


Last edited by radoulov; 03-26-2008 at 07:46 AM..
# 6  
Old 03-26-2008
thanks guyss ... !!!!

Cheers
D
# 7  
Old 03-27-2008
Hi All,

If i have a similar file with no commas to separate the fields, is there any way:

1001DEFG,40000
2002KGRG,3000
2002HDGD,3454
4564GRTR,5656
4659GGTD,10002


to get :

2002KGRG,3000
2002HDGD,3454
4659GGTD,10002

Where i have to get lines based on the first four digits of each line.

Thanks,
D
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut command with dynamic passing of delimiter and position values

Hi All, We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string. ex. echo "A,B,C,D,E" |cut -d "," -f3 echo "A|B|C|D|E"|cut -d "|" -f2 Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies

2. Shell Programming and Scripting

How to retrieve values from XML file and update them in the same position! PLEASE HELP?

Good Day All Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1". I need to to create a script that... (2 Replies)
Discussion started by: JulioAmerica
2 Replies

3. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

4. Shell Programming and Scripting

Need command or script to print all lines from 2nd position to last but one position

hi guys, i want command or script to display the content of file from 2nd position to last but one position of a file abcdefghdasdasdsd 123,345,678,345,323 434,656,656,656,656 678,878,878,989,545 4565656667,65656 i want to display the same above file without first and... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

5. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

6. Shell Programming and Scripting

[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone, I have a bunch of lines with values in field 4 that I am interested in. If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Discussion started by: VagabondGold
2 Replies

7. Shell Programming and Scripting

[Solved] How do i deal with values on multiple lines?

Hi, I have a file which has the contents: sh-4.2# pwd /tmp sh-4.2# cat servernfiles server1 /var/tmp/file server2 /var/tmp/file1 I want to manage each line one after the other. I have this basic script : #!/bin/sh HOST=`cat /tmp/servernfiles | awk '{print $1}'` CMD=`cat... (6 Replies)
Discussion started by: chandika_diran
6 Replies

8. Programming

C program - convert values based on the position

Hey! I'm new to C. I need to covert certain values using C. please see the below. I have figured out the logic to do it. Please provide some hints to do this with C Logic: If first position of POS = 0, shift POS to the left one byte. If third position of POS = 0, move spaces to third... (1 Reply)
Discussion started by: rocker_me2002
1 Replies

9. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

10. Shell Programming and Scripting

BASH: extracting values from multiple lines after a match

Hi there, I have the following output, # raidctl -l RAID Volume RAID RAID Disk Volume Type Status Disk Status ------------------------------------------------------ c0t1d0 IM OK c0t1d0 OK ... (4 Replies)
Discussion started by: rethink
4 Replies
Login or Register to Ask a Question