To select only column starting with a particular value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To select only column starting with a particular value
# 1  
Old 07-06-2011
To select only column starting with a particular value

Hi all,
Am using awk to reformat an existing file
Code:
cat $INP_FILE1 | while read line
do
echo "$line" | nawk ' BEGIN {FS=","}  {print("5",$1,$28,"$27",$26)}' >> $OUT_FILE1
done

my question is, i would like to read lines that are starting with particular value only example

1,12,,2099,IF_TB001, 1
2,12,,2099, , 2
3,,103900002,100,110,103900002.116510.,,,,,EUR,, ,,,,, 47353.17, , , , CT_ACCT, , , , 0000000000, JDE, 3
3,,103900002,100,110,103900002.116510.,,,,,GBP,, ,,,,, -47353.17, , , , CT_ACCT, , , , 0000000000, JDE, 4

like my formatting should happen only on lines starting with 3 other lines startin with 1 and 2 should be discareded

Last edited by vbe; 07-06-2011 at 12:08 PM.. Reason: please use code tags
# 2  
Old 07-06-2011
I didn't catch what you wanted exactly, but here is a start:
Code:
awk '/^3/{print "5",$1,$28,$27,$26 }' OFS=, FS=, INP_FILE1

# 3  
Old 07-06-2011
or
Code:
cat $INP_FILE1|grep ^3 | while read line
do
echo "$line" ...

# 4  
Old 07-06-2011
Thank you...That worked perfectly
# 5  
Old 07-06-2011
Try this, specified some random columns.

Code:
awk -F',' '$1 ~/^3/ { print $1,$2,$3,$6,$7 }' <Input filename>

# 6  
Old 07-11-2011
I have problem here,

my input file has 5 lines starting with 3 but when i use the below code i get output only for 4 lines

Code:
 
cat $FILENAME |grep ^3 | while read line
do
nawk -v H1=$H1 -v H2=$H2 'BEGIN {FS=","} {..some  print formatting..}' >> NEW_FILE
done

is somewith wrong with the above stuff ?

even tried
Code:
 
cat $FILENAME |grep ^3 | while read line
do
echo "$line"| nawk -v H1=$H1 -v H2=$H2 'BEGIN {FS=","} {..some print formatting..}' >> NEW_FILE
done

# 7  
Old 07-11-2011
We agree ^3 means char 3 as the very first char of the line ( so space then 3 is out!)... Is it absolutely the case?
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

SELECT and wrapping to next column

Hi all, Am trying to write a menu driven script using SELECT and if I have more than 4 options, it wraps to the next column. That is if I have 6 choices, items 5 and 6 are in the second column. Is there any settings that control this behavior or is it due to some stty settings? stty -a... (3 Replies)
Discussion started by: newbie_01
3 Replies

3. Shell Programming and Scripting

Select record having different value in second column

I want records which have more than one and different value in the second column on the below sample file. Ex, I have the samle file below :- XYZ 1 XYZ 3 abc 1 abc 1 qwe 2 qwe 1 qwe 3 I want to select XYZ and QWE line only. (6 Replies)
Discussion started by: Sanjeev Yadav
6 Replies

4. Shell Programming and Scripting

select last column

Hi! From a file the format of whichis as in the sample here below, I need to get two files having just 2 columns, being - for the first file - the 2nd than the 1st from the original file; and - for the second file - the LAST then the 1st column of the original file. Moreover, I would sort the... (3 Replies)
Discussion started by: mjomba
3 Replies

5. Programming

select value from 'value' column if the Value2 is having a particular value.

Two columns are there in a table Value and Value2.I need to select a desired value from 'value' column if the Value2 is having a particular value. Ex. Table has values ---------------------------- Value Value2 ---------------------------- 1 GOD ... (6 Replies)
Discussion started by: gameboy87
6 Replies

6. UNIX for Dummies Questions & Answers

to select according to the second column..!!

the input is : 6298 | anna | chennai | 7/4/08 3981 | dastan | bagh | 8/2/07 6187 | galma | london | 9/5/01 3728 | gonna | kol | 8/2/10 3987 | hogja | mumbai | 8/5/09 2898 | homy | pune | 7/4/09 9167 | tamina | ny | 8/3/10 4617 | vazir | ny now how to get the following output : 3987 |... (4 Replies)
Discussion started by: adityamitra
4 Replies

7. Shell Programming and Scripting

SQL select all but not if it is already in an other column

I know I know.. for sure one of the easier mysql statements. But somehow I can not figure out this. I expect to see all distinct items of 'data_12' where 'kwroot' has 'straxx' in, and in the same row 'data_12' ist (not = 'kwsearched' in any existing row) data_12 ... (6 Replies)
Discussion started by: lowmaster
6 Replies

8. Shell Programming and Scripting

How to select and edit on a particular column?

How can I use awk to pick a particular column and work on it? For example, I want to count the number of characters in column10 that are separated by |? Thank you. (2 Replies)
Discussion started by: ivpz
2 Replies

9. UNIX for Dummies Questions & Answers

select first column of file

Hi, Following is my file output 247 Sleep 25439 NULL 259 Sleep 25460 NULL 277 Sleep 15274 NULL 361 Sleep 2 NULL 362 Sleep 202 NULL I want to select only first column to other file How can... (2 Replies)
Discussion started by: kaushik02018
2 Replies

10. Shell Programming and Scripting

select a column

I've a file like this: andrea andre@lol.com october antonio@lol.com marco 45247@pop.com kk@pop.com may pollo@lol.com mary mary@lol.com can I select only the column with email adress? can I utilise a filter with @ ? I want obtain this: ... (2 Replies)
Discussion started by: alfreale
2 Replies
Login or Register to Ask a Question