how to insert the entry inside the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to insert the entry inside the line
# 1  
Old 01-28-2009
how to insert the entry inside the line

Hi
I have a file which contains entry similar to this one:

PX_LIST="2259 2215 270 2635 2874 2713 243 4124 2529 2874 34 477 "

Is there a efficient(short) way to use "awk" or "sed" to enter any number, lets say 7777, as the first number inside the quotes, so the result would look like this:
PX_LIST="7777 2259 2215 270 2635 2874 2713 243 4124 2529 2874 34 477 "

Thanks a lot for any information. -A
# 2  
Old 01-28-2009
Code:
echo 'PX_LIST="2259 2215 270 2635 2874 2713 243 4124 2529 2874 34 477 "' | sed 's/PX_LIST="/&7777 /'

# 3  
Old 01-28-2009
Thanks a lot
# 4  
Old 01-28-2009
Quote:
Originally Posted by aoussenko
Hi
I have a file which contains entry similar to this one:

PX_LIST="2259 2215 270 2635 2874 2713 243 4124 2529 2874 34 477 "

Is there a efficient(short) way to use "awk" or "sed" to enter any number, lets say 7777, as the first number inside the quotes, so the result would look like this:
PX_LIST="7777 2259 2215 270 2635 2874 2713 243 4124 2529 2874 34 477 "

If there is only one line in the file, you don't need sed or awk:

Code:
read line < file
line="${line%%\"*}\"4777 ${line#*\"}"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert text after the first occurance of searched string entry in a file

My server xml file has huge data part of which i'm sharing below. I wish to add the below text held by variable "addthisline" after the closing braces i.e --> once the first </Connector> tag is found. addthisline="I need to be inserted after the comments" Thus my searchstring is... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

How to insert a column inside a dataset with awk?

Hello folks I have a file called fill1.txt which contains: 1 2 2 1 1 2 1 2 my other file is called fill2.txt which contains: 1 2 1 2 2 2 1 2 1 2 1 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 1 2 2 1 Now, I am looking for a awk command which could insert fill1.txt between... (1 Reply)
Discussion started by: sajmar
1 Replies

3. Shell Programming and Scripting

Insert empty columns inside a pipe delimited file

Hi All , I have pipe delimiter file with 11 columns . I need to insert 4 empty columns after column 10 . and After 11 column I need to insert a column which is having the same value for all the rows . My file 1|2|3|4|5|6|7|8|9|10|11 New file ... (11 Replies)
Discussion started by: Hypesslearner
11 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

5. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

6. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

7. Shell Programming and Scripting

Edit date entry inside a file

Hi All, I wanted to edit the date value located at /var/opt/CPsuite-R65/fw1/conf/local.scv. The date entry looks like this : :Signature (">=20100717") How can I update the date value by 1 day every other day while preserving the margins of the whole file in a shell script? I have... (5 Replies)
Discussion started by: achillesxv
5 Replies

8. Shell Programming and Scripting

reading a file inside awk and processing line by line

Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ... (6 Replies)
Discussion started by: Anteus
6 Replies

9. Web Development

SQL Select inside Insert

I have following. . . . $userid = 2 . $query = "select username from users where userid = ".$userid.";"; . $username = $line; $data="Some Data Here"; . $query = "insert into logger (username, data) valuse ($username, $data);"; . I would like to not have 2 database calls. (3 Replies)
Discussion started by: Ikon
3 Replies
Login or Register to Ask a Question