awk program to select a portion of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk program to select a portion of a line
# 1  
Old 01-11-2008
awk program to select a portion of a line

Hi all,
I am new to awk programs.I have a file like this

vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd
vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd
vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd
vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd
vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd

I want to select the text which comes between <LTEXT> and </LTEXT>
This is urgent...Please help..

Thanks in Advance
# 2  
Old 01-11-2008
sed
Code:
# sed 's/.*<LTEXT>\(.*\)<\/LTEXT>.*/\1/g' file
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv

[n]awk
Code:
# awk '{gsub(/.*<LTEXT>|<\/LTEXT>.*/,"");print}' file
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv
aabcdfffvvbbxbcddjbv

# 3  
Old 01-11-2008
Please try this

Code:
sed 's!\(.*\)LTEXT>\(.*\)</LTEXT\(.*\)!\2!' filename

# 4  
Old 01-11-2008
awk program to select a portion of a line

Smilie
Thanks....it worked..!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass command line arguments to awk program?

#!/bin/awk -f BEGIN { FS=":"; } { if ( $7 == "" ) { print $1 ": no password!"; } } I want to execute this program for a particular user to check for his password from the file /etc/passwd (as the input file) and the user details to be given... (1 Reply)
Discussion started by: sri.phani
1 Replies

2. Shell Programming and Scripting

Shell to display portion of a line

Thanks a lot for the code and the explanation. Now my final requirement. I have uploaded 3 files as attachment. Please open the files in Editplus or any other text editor which keeps the formatting. GMDCOM.27936.log.txt------I want to pick only Process request from this file.(Please check... (9 Replies)
Discussion started by: ghosh_tanmoy
9 Replies

3. Shell Programming and Scripting

select entry from consecutive line awk

Hi folks, I have a file with four columns that looks like the following (tab separated) 1 1 1 a 2 2 2 b 3 3 3 c 4 4 4 d I would like to create a file with always 4 columns but where the third entry corresponds to the thirst entry of the next line and so on, to get the following 1 1 2 a... (4 Replies)
Discussion started by: klebsiella
4 Replies

4. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

5. Shell Programming and Scripting

How to grep a portion of line

Mysql log has something like: I want to grep only the portion "ernie-1328697839.1233158" from each line. How to do this? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

6. Shell Programming and Scripting

Print a portion of a line

Hi, I am facing a little problem... I have a line like this : asdcvashfasashXXXXxxxzxcadd:sdcashjqdasdsmgdkdaxdsnd; I want to print just a portion of line i.e starting from left 5 characters from ":" and upto ";" i.e. in this case it would be "xcadd:sdcashjqdasdsmgdkdaxdsnd;" The length of... (2 Replies)
Discussion started by: vanand420
2 Replies

7. Shell Programming and Scripting

select a portion of a file into a CSV

How will i convert a file <LDATE>10-12-07</LDATE><LTIME>13:47:48.553</LTIME><LTEXT>name:anju;city:blore;ph:123</LTEXT> <LDATE>10-12-07</LDATE><LTIME>13:47:48.553</LTIME><LTEXT>name:anju;city:blore;ph:123</LTEXT>... (8 Replies)
Discussion started by: anju
8 Replies

8. Shell Programming and Scripting

Select a portion of file based on query

Hi friends :) I am having a small problem and ur help is needed... I have a long file from which i want to select only some portions after filtering (grep). My file looks like : header xxyy lmno xxyy wxyz footer header abcd xy pqrs footer . . (14 Replies)
Discussion started by: vanand420
14 Replies

9. Shell Programming and Scripting

awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line . Any help is appreciated. thanks arif (4 Replies)
Discussion started by: mab_arif16
4 Replies

10. UNIX for Dummies Questions & Answers

erasing portion of line with sed

hi, I'm trying to use sed to erase everything, and including the ending parenthesis. For example: input: blah blah blah (12355)this is what i want. output: this is what i want. how would i do this? i found an example online that does the opposite: sed \"s|test.*||g\" file1 > file2"; ... (5 Replies)
Discussion started by: gammaman
5 Replies
Login or Register to Ask a Question