10-20-2008
Get string from file after nth symbol
I've got a file, where I want to grab two fields from it. The file isn't fixed format, so all I know is that the two fields are after a certain number of delimiters within the record.
File e.g. as follows:-
"1"^"HEADER"^
"5"^"12345678"^"Smith"^"Dave"^"Mr"^"Research & Development"^"Sheffield"^"ABCDEFGH"^
"9"^"TRAILER"^
if position 2 = '5', then after the 1st ^ write the value between the ^'s to the file, then delimit by a comma (or anything), then after the 7th ^ write the value to the file, so I end up with:-
"12345678","ABCDEFGH"
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
How to I get the nth character from a string in shell script. For instance, I have a string London. I want to get, say the first character (L) from the string. How do I do this in unix shell?
Thankx (4 Replies)
Discussion started by: toughman
4 Replies
2. Shell Programming and Scripting
Hi all,
I have file with following content
...........................
..........TEST..........
..........TEST..........
.....................
.....TEST..........
.....................
.....................
.....TEST..........
I want to replace nth "TEST" with "OK" using... (4 Replies)
Discussion started by: uttamhoode
4 Replies
3. Shell Programming and Scripting
Hello All,
How to replace a string in nth line of a file using sed or awk.
For Ex: test.txt
Line 1 : TEST1 TEST2 TEST3
Line 2 : TEST1 TEST2 TEST3 TEST4
Line 3 : TEST1 TEST2 TEST3 TEST5
Line 4 : TEST1 TEST2 TEST3 TEST6
Line 5 : TEST1 TEST2 TEST3 TEST7
i want to go to 4th line of a... (1 Reply)
Discussion started by: maxmave
1 Replies
4. Shell Programming and Scripting
Hi
I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)
Data in File.
<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies
5. Shell Programming and Scripting
How do I check that a string $AA22CC3 starts with the "$" symbol ?
I have tried :
checksum='$AAB3E45'
echo $checksum
case $checksum in
$* ) echo success ;
esac
Thanks ... (4 Replies)
Discussion started by: cillmor
4 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I would like to extract a pattern from a line. The first two characters will always be the same in this pattern, but the proceeding numbers will not be, and the pattern will always be 6 characters long. I would like to get the entire pattern up to a certain symbol, in this case, a period.
... (3 Replies)
Discussion started by: goodbenito
3 Replies
7. Shell Programming and Scripting
Hi,
I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g.
> cat file1
banana
apple
orange
apple
banana
pear
tangerine
apple
> cat file2
I don't like apples
What would be the sed command to insert... (5 Replies)
Discussion started by: dimocn
5 Replies
8. Shell Programming and Scripting
I have file in which the data looks like this,
01,0000000,xxxxxxx/
02,xxxxxxxx,yyyyyy/
03,test1,41203016,,/
01,0000000,xxxxxxx/
02,xxxxxxxx,yyyyyy/ ... (16 Replies)
Discussion started by: r@v!7*7@
16 Replies
9. Shell Programming and Scripting
I wanted to search for a string and replace it with other string from nth column of a file which is comma seperated which I am able to do with below
# For Comma seperated file without quotes
awk 'BEGIN{OFS=FS=","}$"'"$ColumnNo"'"=="'"$PPK"'"{$"'"$ColumnNo"'"="'"$NPK"'"}{print}' ${FileName} ... (5 Replies)
Discussion started by: Amit Joshi
5 Replies
10. Shell Programming and Scripting
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
WRITE(1) General Commands Manual WRITE(1)
NAME
write - write to another user
SYNOPSIS
write user [ ttyname ]
DESCRIPTION
Write copies lines from your terminal to that of another user. When first called, it sends the message
Message from yourname@yoursystem on yourttyname at time...
The recipient of the message should write back at this point. Communication continues until an end of file is read from the terminal or an
interrupt is sent. At that point write writes `EOT' on the other terminal and exits.
If you want to write to a user who is logged in more than once, the ttyname argument may be used to indicate the appropriate terminal name.
Permission to write may be denied or granted by use of the mesg command. At the outset writing is allowed. Certain commands, in particu-
lar nroff and pr(1) disallow messages in order to prevent messy output.
If the character `!' is found at the beginning of a line, write calls the shell to execute the rest of the line as a command.
The following protocol is suggested for using write: when you first write to another user, wait for him to write back before starting to
send. Each party should end each message with a distinctive signal--(o) for `over' is conventional--that the other may reply. (oo) for
`over and out' is suggested when conversation is about to be terminated.
FILES
/var/run/utmp to find user
/bin/sh to execute `!'
SEE ALSO
mesg(1), who(1), mail(1)
7th Edition November 27, 1996 WRITE(1)