tough parsing


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tough parsing
# 1  
Old 05-31-2009
tough parsing

I have a string as "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD"

I want to parse the string and store it in 3 different variables.

$period (should get value 20090531)
$client (should get value "Clayton Lumbar company")
$dest (should get value MD)

How can I do this in a shell script command?

Last edited by paruthiveeran; 05-31-2009 at 04:02 PM..
# 2  
Old 06-01-2009
period=`cut -d"=" -f2 file.txt | cut -d " " -f2`
name=`cut -d"=" -f3 file.txt | cut -d " " -f 2,3`
dest=`cut -d"=" -f4 file.txt`

# echo $period
20090531
# echo $name
Clayton Lumbar
# echo $dest
MD

Smilie
# 3  
Old 06-01-2009
Code:
echo "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD" | awk '{
 gsub(/Period= |Client Name= |Destination= /,"|")
 m=split($0,a," ")
 print $0
}'

# 4  
Old 06-02-2009
Quote:
Originally Posted by ghostdog74
Code:
echo "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD" | awk '{
 gsub(/Period= |Client Name= |Destination= /,"|")
 m=split($0,a," ")
 print $0
}'

Thanks, it worked
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. IP Networking

This looks like a tough routing issue

Hi, The default gateway (172.17.220.1) cannot be pinged via the default interface bond0 (172.17.220.231), but can be pinged via interface eth1 (10.201.135.73). # ping -I eth1 172.17.220.1 PING 172.17.220.1 (172.17.220.1) from 10.201.135.73 eth1: 56(84) bytes of data. 64 bytes from... (4 Replies)
Discussion started by: aixlover
4 Replies

2. Shell Programming and Scripting

A very tough exercise

hello everyone!:) I have an exercise which I think is difficult for beginner like me. Here is the exercise Create a shell script, which takes a directory as command line argument. Script displays ten first lines from every text file in that directory. After displaying the lines from the... (1 Reply)
Discussion started by: googlevn
1 Replies

3. UNIX for Advanced & Expert Users

Tough Oracle Logic in Ux

How Can this logic be implemented in Unix SELECT B.SERVICE_TYPE || '|' || B.TOTAL_TYPE || '|' || B.CALL_INDICATOR || '|' || B.A_NUMBER || '|' || B.APN || '|' || B.DAY || '|' || B.HOUR ||... (3 Replies)
Discussion started by: magedfawzy
3 Replies

4. UNIX for Advanced & Expert Users

Tough Substituion command

I have lines like: Mg2.qns W=0.175u Mg2.qpsb W=0.175u Mg4.qns W=0.175u Mg4.qpsb W=0.175u Which I need to become: Mg2.qns W=wmg2qns Mg2.qpsb W=wmg2qpsb Mg4.qns W=wmg4qns Mg4.qpsb W=wmg4qpsb To acheive this individually line by line I use a command like:... (3 Replies)
Discussion started by: ggggdddd
3 Replies

5. Programming

Tough makefile question

At my company, we build some stuff using a makefile. While the makefile script is running, a developer may check in a newer version of a source file. The problem is, when we next run the make command, the target file isn't rebuilt, because the date of the target is after the dependency. Any... (1 Reply)
Discussion started by: mbbeaubi
1 Replies

6. Shell Programming and Scripting

Seems the Shell Script is very tough

Guys plz respond. (1 Reply)
Discussion started by: prince_of_focus
1 Replies
Login or Register to Ask a Question