Search and replace - pattern-based


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and replace - pattern-based
# 1  
Old 10-10-2011
Search and replace - pattern-based

Hey folks!

I am new to shell-scripting, but I have a problem that I would like to solve using a script. I create very large html forms, used for randomized trials. In these forms, each question is supplied with a variable that looks something like this: PROJECT_formNN
Where NN is the question number. Say I need to put in a question in the middle, the whole line of questions after this one are then put out of order.

Solution?

/Roevhat
# 2  
Old 10-10-2011
I am not clearly but i try to write something.
For exa you have some questions in a file that named 'questions'
Code:
#!/bin/bash
q=questions
nn=$(wc -l <$q)
NN=1
while read -r quest
 do
   echo "$quest">PROJECT_form$NN
   ((NN++))
 done<$q

Code:
# cat questions
What is your name?
Where are you from?
How about?
Are you joking me?
What is your favourite singer?

Code:
# for i in {1..5}
> do
> cat PROJECT_form$i
> done
What is your name?
Where are you from?
How about?
Are you joking me?
What is your favourite singer?

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Search and replace within pattern

Hi Guys! Unix newbie here! Have a requirement for which I have been scouting the forums for a solution but has been out of luck so far :( I have a file which contains the following:- TEST1|TEST2|"TEST3|1@!2"|TEST5 My sed command should result in either one the following output:-... (6 Replies)
Discussion started by: hishamzz
6 Replies

2. UNIX for Dummies Questions & Answers

Updating value based on search pattern

I have a file with following data <Field FieldName="CHCFA21_01_01" FieldType="Text"> <Output CapturedValue=""> <DataSource Name="" Value="" /> </Output> </Field> <Field FieldName="CHCFA21_01_02" FieldType="Date"> <Output CapturedValue=""> ... (1 Reply)
Discussion started by: nsuresh316
1 Replies

3. Shell Programming and Scripting

Search for a pattern and replace. Help needed

I have three variables $a, $b and $c $a = file_abc_123.txt $b = 123 $c = 100 I want to search if $b is present in $a. If it is present, then i want to replace that portion by $c. Here $b = 123 is present in "file_abc_123.txt", so i need the output as "file_abc_100.txt' How can this be... (3 Replies)
Discussion started by: irudayaraj
3 Replies

4. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

5. Shell Programming and Scripting

perl:: search for tow pattern and replace the third pattern

Hi i want to search two pattern on same line and replace onther pattern.. INPut file aaaa bbbbb nnnnnn ttttt cccc bbbbb nnnnnn ppppp dddd ccccc nnnnnn ttttt ffff bbbbb oooooo ttttt now i want replace this matrix like.. i want search for "bbbbb","nnnnnn" and search and replace for... (4 Replies)
Discussion started by: nitindreamz
4 Replies

6. Shell Programming and Scripting

Replace Text Based On Pattern

Hi I'm trying to replace text in a file based upon a pattern. The pattern I'm looking for is: <styleURL>#style0002</styleURL> <name>#######6105#######</name>The # are seven alphanumeric characters before and after 6105. I need it to replace that with this recursively: ... (4 Replies)
Discussion started by: Grizzly
4 Replies

7. Shell Programming and Scripting

search a pattern and replace the whole line

Hi All, I have a requirement where I have to find a pattern in a file and comment the whole line containing the search pattern. Any ideas in shell is welcome. Thanks in advance, Regards, Arun (3 Replies)
Discussion started by: arun_maffy
3 Replies

8. Shell Programming and Scripting

search replace pattern containing slashes

Need help in finding pattern then replacing pattern that contains multiple slashes .. ex . <imgp src="Attention_web.eps.jpg" align="left"> <imgp src="NewToday062308.eps.jpg"> replace with <imgp src="/ww2/adpay/liner/Attention_web.eps.jpg" align="left"> <imgp... (2 Replies)
Discussion started by: aveitas
2 Replies

9. Shell Programming and Scripting

SED Search Pattern and Replace with the Pattern

Hello All, I have a string "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031", and I just want to extract LLSV1, but I dont get the expected result when using the sed command below. # echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | awk '{print... (4 Replies)
Discussion started by: racbern
4 Replies

10. Shell Programming and Scripting

Search for a Pattern and Replace

Hello All, Can you help me with this , I need to search a pattern replace it with the new pattern in all the files in a directory. what would be the easiest way to do that? Thanks in advance. :) Sam, (6 Replies)
Discussion started by: sbasetty
6 Replies
Login or Register to Ask a Question