parsing a string in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing a string in a shell script
# 8  
Old 08-05-2004
Also the original question does have an answer....

Code:
typeset  -L4 first4
typeset -R4 last4
x="welcome"
first4=$x
last4=$x
echo $first4 $last4

Also you can discard the first 4 or the last 4.
Code:
last_part=${x#????}
first_part=${x%????}
echo $first_part  $last_part


Last edited by rbatte1; 01-26-2017 at 07:23 AM..
# 9  
Old 09-21-2004
Hammer & Screwdriver awk variable

Does anyone know how to assign the variable from resulted from awk to the shell program?


Sample:

Code:
echo questionlabel |awk '{print length($0)}
13


I would like to use 13 as a variable in my shell program.
How do I assign 13 to a variable after this?


Thanks,

Last edited by rbatte1; 01-26-2017 at 07:23 AM..
# 10  
Old 09-21-2004
using ksh:

Code:
i=$(echo questionlabel |awk '{print length($0)}')

To parse the four firts characters of a string:
Code:
echo "welcome" | cut -c4


Last edited by rbatte1; 01-26-2017 at 07:23 AM..
# 11  
Old 01-27-2006
Hi,

Suppose I have a file such as

Code:
....
.....
.....
Start time = 10:10:00
Number of records loaded = 2074921
End time = 11:23:12
....
.....

...and I want to extract the number of records loaded i.e. 2074921, how do I go about doing it?

Last edited by rbatte1; 01-26-2017 at 07:24 AM..
# 12  
Old 01-27-2006
Quote:
Originally Posted by Eddie_The_Head
Hi,

Suppose I have a file such as

Code:
....
.....
.....
Start time = 10:10:00
Number of records loaded = 2074921
End time = 11:23:12
....
.....

...and I want to extract the number of records loaded i.e. 2074921, how do I go about doing it?
You should have started a new thread rather than continuing with an old thread.

If your output remains in the format you have given i.e. if it includes the line
Number of records loaded, then do this

Code:
sed -n -e 's_Number of records loaded = \([0-9][0-9]*\)_\1_p' your.input.file


Last edited by rbatte1; 01-26-2017 at 07:24 AM..
# 13  
Old 01-27-2006
Hello,

Code:
cat file | awk -F= '/^Number of records loaded/ {printf $2}'

--
Solea

Last edited by rbatte1; 01-26-2017 at 07:24 AM..
# 14  
Old 01-27-2006
Thanks a lot Vino, Solea...
guess i should haave started a new thread...
i posted it here since it was related to parsing...
sorry for breaking the thread guys...and thanks for the help..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with understanding this regex in a Perl script parsing a 'complex' string

Hi, I need some guidance with understanding this Perl script below. I am not the author of the script and the author has not leave any documentation. I supposed it is meant to be 'easy' if you're a Perl or regex guru. I am having problem understanding what regex to use :confused: The script does... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Parsing XML using shell script

Well, issue is i have to parse this script to get the VERSION: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleAllowMixedLocalizations</key> ... (9 Replies)
Discussion started by: zorosinister
9 Replies

3. Shell Programming and Scripting

parsing using shell script

I have a file parameters.txt which contains 151524 151525 I have another file OID.csv which contains NE Version Object Type ID SDK param name Object OID test1 Start: 4.2 End: 4.2 pan 151524 speed ... (5 Replies)
Discussion started by: LavanyaP
5 Replies

4. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

5. Shell Programming and Scripting

String parsing in Korn Shell

Hi everybody, I have a string stored in a variable called record: record="SNMPv2-SMI::ent.9.9.43.1.3.9.2 = Timeticks: (177330898) 20 days, 12:35:08.98" I want to write some regular expressions good for Korn Shell to extract the number between parenthesis, in this case 177330898, and put it in... (3 Replies)
Discussion started by: omoyne
3 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. UNIX for Dummies Questions & Answers

shell script parsing with sed

#I'm quite new to scripting and my boss has asked me to solve a simple problem and sadly, I can't figure out how to do it. Any help is appreciated. :confused: #The following is a small shell script and the output that it produces for google.com. #!/bin/sh whois $1 | grep "Name Server"... (5 Replies)
Discussion started by: jjamd64
5 Replies

8. Shell Programming and Scripting

Parsing a line in Shell Script

I have record line somthing like below with first line showing char spacing not real record line 1 | 2 | 3rd Field--------------|-4th field--| This is charcatersapcing of line DF20000000000000000130.7890000000750 I shoudl get two line from above line 1st line should 1 | 2 | 3rd... (3 Replies)
Discussion started by: unishiva
3 Replies

9. Shell Programming and Scripting

Parsing a file in Shell Script

Hi, I have a requirement. I have an application which can take a file as inputs. Now the file can contain any number of lines. The tool has to pick up the first uncommented line and begin processing it. For example the file could be like this: #MANI123|MANI1234 #MANI234|MANI247... (4 Replies)
Discussion started by: sendhilmani123
4 Replies

10. Shell Programming and Scripting

shell script argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies
Login or Register to Ask a Question