parse of lines with different delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse of lines with different delimiters
# 8  
Old 05-16-2008
Is not the nicer solution, but you can try:

Code:
#! /usr/bin/ksh
#set -x
touch file_1
touch file_2
touch large
touch final
if [ -f large ]
then
cat /dev/null > final
fi
if [ -f final ]
then
cat /dev/null > final
fi
cat /dev/null > file_1
cat /dev/null > file_2
while read line
do
        echo $line | grep subject >> file_1
        echo $line | grep message >> file_2
done < $1
paste file_2 file_1 > large
while read line
do
SUB=$(echo $line | awk -F"." '{print $5}')
SD=$(echo $line | cut -b13-22 | sed 's/:/-/g')
SP=$(echo $line | cut -b40)
TS=$(echo $line |cut -b84-99 | sed 's/:/-/' | sed 's/:/-/')
VP=$(echo $line |cut -b112-114)
echo "$SD,$SUB,$TS,$SP,$VP" >> final
done < large
rm large file_1 file_2


_________

- execution ./script file_name
- the result is the file final
# 9  
Old 05-16-2008
Without gensub:

Code:
#!/usr/bin/awk -f
BEGIN {FS=","; OFS=","}
{
                one = substr($1, match($1, /subject=BMRA.BM./) + 17, 10)
                sub(/\..+/, "", one)
                print substr($2, match($2, /[0-9][0-9][0-9][0-9]:[0-9][0-9]:[0-9][0-9]/), 10),
                one, 
                substr($5, match($5, /TS=/) + 3, 19),
                substr($3, match($3, /SP=/) + 3),
                substr($6, match($6, /VP=/) + 3)
}

# 10  
Old 05-16-2008
[QUOTE=nathasha;302195904
tmp3A=${tmp3:0:10}: bad substitution[/QUOTE]

Then you either are not using a recent version of ksh93 (later than 1999) or your data structure has changed from what you provided as a sample.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines only with 3 delimiters

Hi All, my file has following Data 04:38:34 02:03 24:40 02:09:58 09:13 03:04:11 02:09:58 35:00 I want to display only lines with 3 fields. ie.. 04:38:34 02:09:58 03:04:11 (6 Replies)
Discussion started by: Arunselvan
6 Replies

2. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

3. Shell Programming and Scripting

Concatinating the lines based on number of delimiters

Hi, I have a problem to concatenate the lines based on number of delimiters (if the delimiter count is 9 then concatenate all the fields & remove the new line char bw delimiters and then write the following data into second line) in a file. my input file content is Title| ID| Owner|... (4 Replies)
Discussion started by: bi.infa
4 Replies

4. Shell Programming and Scripting

parse lines

I have file which is having 500 lines. I want to get the first 100 lines then sleep, then again next 100 lines sleep so now till the end of the file. Can someone tell me in perl and bash. also i want to do it in threads. Thanks.. (6 Replies)
Discussion started by: Anjan1
6 Replies

5. Shell Programming and Scripting

How to parse a numeric string without any delimiters?

Hi , I have a number say 12345001 which needs to be parsed. Its a number that has no delimiters.I have to read the last three digits and then the rest of digits irrespective of the total length of the number. The digits then have to be swapped and changed to a fixed length. The fillers to be... (10 Replies)
Discussion started by: Sheel
10 Replies

6. UNIX for Dummies Questions & Answers

How to parse 2 particular lines from Command output

Hi All, I need help on the following req. I am getting output of a command as follows: 16377612 total memory 3802460 used memory 2827076 active memory 681948 inactive memory 12575152 free memory 477452 buffer memory I want to compute used... (1 Reply)
Discussion started by: mailsara
1 Replies

7. Shell Programming and Scripting

Parse out specific lines

Hello, For the life of me, I can't figure out how to extract only certain lines of a file. For example, the file contains: project.max-sem-ids privileged 1.02K - deny - system 16.8M max deny ... (2 Replies)
Discussion started by: PointyWombat
2 Replies

8. Shell Programming and Scripting

commenting out lines between two delimiters

Hi All, I am struggling to get my head around the following issue. I am having to comment out lines between two delimiters by placing an asterix in position 7 but retain all lines in the file and in the same order. so for example a file containing: ... ... DELIM1 ... ... DELIM2... (2 Replies)
Discussion started by: Bruble
2 Replies

9. Shell Programming and Scripting

Parse and count lines

I have a data file in the following format (refer to input file) with multiple lines containing some information. I need an output file to loop thorough the input file with summarized information as seen below (refer to output file) ‘Date Time' and ‘Beta Id' input file values should be concatenated... (7 Replies)
Discussion started by: shekharaj
7 Replies

10. Shell Programming and Scripting

Insert lines between delimiters

I'm working with a file like: somestuff somemorestuff ... someadditionalstuff STARTTAG ENDTAG someotherstuff somecoolstuff ... somefinalstuffI've got some text (either in a file or piped) to put between STARTTAG and ENDTAG. I was thinking something like grepping for the line number of... (2 Replies)
Discussion started by: BMDan
2 Replies
Login or Register to Ask a Question