Print part of line excluding one column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print part of line excluding one column
# 1  
Old 02-16-2011
Print part of line excluding one column

Hi,

I have data which is having '|' as delimiter and have lobfilename/locations in the data.
Ex:
Code:
1200|name1|lobfilename.0.600|abcd
1201|name2|lobfilename.600.1300|abcd

My requirement is to print part of the line till the lobfilename and write to a different file and also print the remaining part
So output should be
Code:
1200|name1|abcd
1201|name2|abcd

This lobfilename column can be variable- it could be in the middle of the data or the end of the data for different files.
So I want to be able to write a generic script to identify the no. of the lobfilename column (n) and print everything upto that point (1 to n-1 columns data) and also after the lobfilename column (n+1 till end of data) for all lines in the file.
Could you please help me with the same ?

Last edited by joeyg; 02-16-2011 at 10:02 AM.. Reason: Please use CodeTags around data
# 2  
Old 02-16-2011
lob field?

What defines the lob field?
Is it the existence of
text.number.number ?
# 3  
Old 02-16-2011
Hi Joeyg,

Yes, lobfield is defined by lobfilename.lob.<startposition>.<length>
startposition and length is the substr of chars in the actual lobfile.
# 4  
Old 02-16-2011
Code:
 $ ruby -F"\|" -ane 'puts $F.select{|x|!x[/^lobfile/]}.join("|")' file 
1200|name1|abcd 
1201|name2|abcd

This User Gave Thanks to kurumi For This Post:
# 5  
Old 02-16-2011
Code:
nawk -F"\|" '{x=$1;for(i=2;i<=NF;i++){x=($i~/^lob.*\.[0-9]+\.[0-9]+$/)?x:x FS $i};print x}' infile

This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (3 Replies)
Discussion started by: Ebk
3 Replies

2. AIX

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (2 Replies)
Discussion started by: Ebk
2 Replies

3. Shell Programming and Scripting

Print next line beside preceding line on column match

Hi, I have some data like below: John 254 Chris 254 Matt 123 Abe 123 Raj 487 Moh 487 How can i print it using awk to have: 254 John,Chris 123 Matt,Abe 487 Raj,Moh Thanks. (4 Replies)
Discussion started by: james2009
4 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

extracting part of a line excluding particular word from it

here is the line on which i want to process `empNo` int(13) NOT NULL AUTO_INCREMENT, it sometimes doesnt have comma at the end too `empNo` int(13) NOT NULL AUTO_INCREMENT i want to extract all except "AUTO_INCREMENT" not only this line i ,want the code to work on any line if it has... (5 Replies)
Discussion started by: vivek d r
5 Replies

6. Shell Programming and Scripting

read file line by line print column wise

I have a .csv file which is seperated with (;) inputfile --------- ZZZZ;AAAA;BBB;CCCC;DDD;EEE; YYYY;BBBB;CCC;DDDD;EEE;FFF; ... ... reading file line by line till end of file. while reading each line output format should be . i need to print only specific columns let say 5th... (2 Replies)
Discussion started by: rocking77
2 Replies

7. Shell Programming and Scripting

How to print last column of line

Hello folks, Please guide me i have a file file.txt that have below text. PETER JOHN peter@example.com John Col john@example.com Sara Paul sara@example.com I just want to extract only email address list. (5 Replies)
Discussion started by: learnbash
5 Replies

8. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies

9. Shell Programming and Scripting

column 1 line transitions part two!

I know I have already asked a similar question and the answer was awesome!...But it turns out I need something slightly different. I have a space delimited text file with thousands of lines, COLA.TXT that looks for example like this: AA 123 456 789 AA 987 987 987 AA 987 988 888 AA 999 999 999... (7 Replies)
Discussion started by: ajp7701
7 Replies

10. UNIX for Advanced & Expert Users

Print the line containing the maximum value in a column

Dear all! I want to find the maximum value in two specific columns with numbers, and then print the entire line containing this value. The file may look like: 1001 34.5 68.7 67 1002 22.0 40.1 32 1003 11.3 34.8 45 I want to find the maximum value within column 2... (22 Replies)
Discussion started by: kingkong
22 Replies
Login or Register to Ask a Question