Extract values froma line in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract values froma line in file
# 1  
Old 06-19-2014
Extract values froma line in file

p.txt
Code:
T|DCNT=100|RECCHK=22222.2|PERCHK=32323|#

I want to extract the value of 100 22222.2 and 32323 and assign it to variable
x1,y1,z1
Code:
x=`cut -f2 -d "=" p.txt`
 x1=`echo $x | cut -f1 -d "|" `
y=`cut -f3 -d "=" p.txt`
y1=`echo $y | cut -f1 -d "|" `
z=`cut -f4 -d "=" p.txt`
z1=`echo $z | cut -f1 -d "|" `


Last edited by bartus11; 06-19-2014 at 03:15 PM.. Reason: Please use [code][/code] tags, not "[data][data]".
# 2  
Old 06-19-2014
Code:
echo 'T|DCNT=100|RECCHK=22222.2|PERCHK=32323|#' | awk -F'[|=]' '{for(i=2;i<NF;i=i+2) print $(i+1)}'

# 3  
Old 06-19-2014
Code:
IFS='|=' read _ _ x1 _ y1 _ z1 _ < p.txt

These 2 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 06-19-2014
Code:
 
echo 'T|DCNT=100|RECCHK=22222.2|PERCHK=32323|#' | (
  IFS='=|'
  read a a x1 a y1 a z1 a
  . . . .
 )

This User Gave Thanks to DGPickett 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

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. UNIX for Beginners Questions & Answers

To extract values after the maximum value in a txt file

Hello, I'm new to scripting and I need to write a bash script. Here is example of file on which I'm working: 0.3092381 0.3262799 0.3425480 0.3578379 0.3719490 0.3846908 0.3958855 0.4053738 0.4130160 0.4186991 0.4223357 ... (1 Reply)
Discussion started by: jeo_fb
1 Replies

3. Shell Programming and Scripting

Extract values in a line using awk

hello all, I need your help in extracting values of some parameter within a line using awk. for example: i have the below line available in a file and i want to extract the values of only CustomerId, s_PackageId and s_HZINumbers in order the result to be as ... (13 Replies)
Discussion started by: nael_najib
13 Replies

4. Shell Programming and Scripting

Find and extract values from one file and update other

Gents, Kindly can you help me to update a file extracting the data from other file. I have: file1 The key in this file is substr($0,4,21), and I need to update the columns 6 and 7 using the information for file2. S 21133.00 21535.00 1 0 919088.8 1843754.5 ... (2 Replies)
Discussion started by: jiam912
2 Replies

5. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

6. UNIX for Dummies Questions & Answers

Extract Unique Values from file

Hello all, I have a file with following sample data 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26... (5 Replies)
Discussion started by: simonsimon
5 Replies

7. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

8. UNIX for Dummies Questions & Answers

Print values of a string froma file

Hi, I have a problem in getting values of a specific string on a file, can you please help me what command or script that I will use to get it? I have a file with the following sample contents. I need to print the values of time. The time sometimes appears on column 2 or column 3. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies

9. UNIX for Dummies Questions & Answers

how to extract a substring froma file

hi all, I'm really newbie on this and I need some help. how is the best way to extract a strig or substring from a each line in a file. e.g. I want to print only this ERROR=JUD+the followed numbers from one line like this one, considering the numbers change related to different errors ... (1 Reply)
Discussion started by: morena
1 Replies

10. Shell Programming and Scripting

Extract values from log file

I would like to write a shell script that will parse through a file similar to the sample below. The data in the file is redirected from rsync into a log file. I would like to call a shell script to parse through and pick out the number beside the percent sign inside the parentheses in the last... (5 Replies)
Discussion started by: wdympcf
5 Replies
Login or Register to Ask a Question