Search pattern between two quotes and make 1 row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search pattern between two quotes and make 1 row
# 1  
Old 11-22-2017
Search pattern between two quotes and make 1 row

Hi All,

My file

Code:
cat file
" test1 test1 "
" test1 test1
test1 test1"
"test1 test1
test1 test1
test1 test1 "

How to achieve this
i want the result:
Code:
cat file
test1 test1
test1 test1 test1 test1
test1 test1 test1 test1 test1 test1


Moderator's Comments:
Mod Comment Please use CODE (not QUOTE) tags as required by forum rules!

Last edited by RudiC; 11-22-2017 at 05:09 AM.. Reason: Changed QUOTE to CODE tags.
# 2  
Old 11-22-2017
Any attempts / ideas / thoughts from your side?
# 3  
Old 11-22-2017
No sir in shell scripts, but im working on notepad++ with regular expression

Code:
find: [^"]*"([^"]+)"[^"]*
replace: \1

I can get the pattern between the two quotes but I cant make it in one line.

Last edited by Scott; 11-22-2017 at 06:02 AM.. Reason: Code tags, please...
# 4  
Old 11-22-2017
One option:
Code:
awk '{while (!/"$/) {getline X; $0 = $0 " " X}; gsub (/ *" */, _)} 1' file
test1 test1
test1 test1 test1 test1
test1 test1 test1 test1 test1 test1

or
Code:
sed  '{:L; N; $!bL;}; s/\n/ /g; s/ *\(" *\)\+/\n/g; s/^\n\|\n$//g; ' file
test1 test1
test1 test1 test1 test1
test1 test1 test1 test1 test1 test1


Last edited by RudiC; 11-22-2017 at 06:31 AM..
This User Gave Thanks to RudiC For This Post:
# 5  
Old 11-22-2017
Thanks a lot Sir, This is working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add double quotes to the words after given pattern

Hi, I have a text file with different results and I would like to add single quotes to the value after the given pattern '=' This would be the original text file: user_id=7492 and key=clickid; user_id=7867 and key=clickid; user_id=8649 and key=clickid; And I would like the output to be... (9 Replies)
Discussion started by: mac-arrow
9 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

4. Shell Programming and Scripting

Search replace strings between single quotes

Hi All, I need to serach and replace a strings between single quote in a file. My file has : location='/data1/test.log' and the output needed is location='/data2/test_dir/test.log' pls if anybody know this can be done in script sed or awk. I have a script, but it's... (6 Replies)
Discussion started by: mnmonu
6 Replies

5. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

6. Shell Programming and Scripting

how to make pattern search dynamic in awk

Hi, I have a data in a file like below - andy 22 abc 30000 wallstreet paul 30 xyz 40000 martstreet john 35 abc 50000 martstreet I want to search number of employees working in a particular company. Below query executes perfectly - awk '/abc/{ COUNT ++; }END { print "number of... (3 Replies)
Discussion started by: shell123
3 Replies

7. Shell Programming and Scripting

print pattern within double quotes

Hi All, I have multiple lines in a file like:- "abc" def "ghi" jkl "mno" 1 I want to print in output:- abc/ghi/mno 1 How can I do this in perl? Regrds, Nilabh -----Post Update----- Additional info:- The last field of the file should be output as it is.In the above example 1 is... (6 Replies)
Discussion started by: nilabh_s
6 Replies

8. Shell Programming and Scripting

repeated column data filter and make as a row

I need to get the output in row wise for the repeated column data Ex: Input: que = five ans = 5 que = six ans = 6 Required output: que = five six ans = 5 6 Any body can guide me?"""""" (2 Replies)
Discussion started by: vasanth_vadalur
2 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

Split a record ( in a row) and make it as new row

Hi All, The following is the scenario id name -------------- 1 William;Johnson 2 Azim;Abdul 3 Grasim . . etc.... I need the following output id name -------------- 1 William 1 Johnson 2 Azim (2 Replies)
Discussion started by: kottursamy
2 Replies
Login or Register to Ask a Question