09-28-2012
Quote:
cat 123.txt
START|one|two|three|four|five|six|seven
START|one|two|three|four|five|six|seven|eight|nine
START|one|two|three|four
perl -lne 'BEGIN{$occurence = 3 }{ @out=split /\|/ ; $out[$occurence] = "here" ; print join "|" , @out } ' 123.txt
START|one|two|here|four|five|six|seven
START|one|two|here|four|five|six|seven|eight|nine
START|one|two|here|four
---------- Post updated at 04:00 AM ---------- Previous update was at 04:00 AM ----------
Quote:
perl -lne 'BEGIN{$occurence = 3 }{ @out=split /\|/ ; $out[$occurence] = "here" ; print join "|" , @out } ' 123.txt
START|one|two|here|four|five|six|seven
START|one|two|here|four|five|six|seven|eight|nine
START|one|two|here|four
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I'm a newbee to Unix shell scripting.
I want to write a shell script that inserts a new String(name&value pair) into a file(s) at a particular place.I willl have to write one script which when executed should insert a new variable in all the files in that particular directory.
Say for eg:... (4 Replies)
Discussion started by: 2tbee
4 Replies
2. Shell Programming and Scripting
i have a file contains like this:
i want to create a script that will insert a comma "." after the 10th character so it would be look like this
thanks in advance (5 Replies)
Discussion started by: dakid
5 Replies
3. Shell Programming and Scripting
hi all... i got some requirment where i need to insert some values into first record of flat file. i am using perl for that job.
var1=456
var2=789
echo `perl -p -i -e "s/U/\${var1}U${var2}/g;" myFile.txt`
but it is writing into all records which has U.... can anyone help me out in this... (7 Replies)
Discussion started by: shreekrishnagd
7 Replies
4. UNIX for Dummies Questions & Answers
Hey Everybody,
I am having much trouble figuring this out, as I am not really a programmer..:mad:
Datafile.txt
Column0 Column1 Column2
ABC DEF xxxGHI
I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies
5. Shell Programming and Scripting
Hey,
I have 10 lines of text ... And I would like to Insert prefix for each line with static text.
perl -pi -e 's/()/$1 TEST$./' data.txt
Each line will have different static prefix, Code above works perfectly for 1st line ... I'm just not sure how I can run same command for 2nd line 3rd... (4 Replies)
Discussion started by: NDxiak
4 Replies
6. Shell Programming and Scripting
print "1.readfromfile\n2.add_ex1(4,5)\n3.add_ex2(11,5)\n4.add_ex3(9,3)\n5.add_ex4(91,4)\n";
How to do it in this form:
print "1.readfromfile\n
2.add_ex1(4,5)\n
3.add_ex2(11,5)\n
4.add_ex3(9,3)\n
5.add_ex4(91,4)\n"; (3 Replies)
Discussion started by: cola
3 Replies
7. Shell Programming and Scripting
Hi Experts,
I need to insert a sting into another string at a specified position. Like the below.
Regards,
Tin-Tin (3 Replies)
Discussion started by: tinufarid
3 Replies
8. Shell Programming and Scripting
Hi everyone,
I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email.
Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string.
GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies
9. Shell Programming and Scripting
Hi everyone,
I am trying to insert a single very long string as the first line of a file,
So the following sed commands does what I want;
sed '1i\"","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"' file.txt
Think that all the... (3 Replies)
Discussion started by: hayreter
3 Replies
10. Shell Programming and Scripting
Hi,
I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file.
Example of the SQL will be
For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING.
I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies