Align or move paragraph right


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Align or move paragraph right
# 8  
Old 03-18-2012
If your on Solaris you may need nawk instead of awk

Try this:

Code:
nawk '
  /larry/ { gsub(/\n/, "\n    "); print "    "$0}
  /sally/||/booby/' RS= FS="\n" ORS="\n\n" IGNORECASE=1 infile

# 9  
Old 03-18-2012
Hello thankyou very much it really worked well, however it seemed to only indent the paragraph by a few spaces, is it possible to increase the spaces or indent - perhaps by 2 tabs?
Thankyou again
Regards
# 10  
Old 03-18-2012
Sure, here is two tab chars:

Code:
nawk '
  /larry/ { gsub(/\n/, "\n\t\t"); print "\t\t"$0}
  /sally/||/booby/' RS= FS="\n" ORS="\n\n" IGNORECASE=1 infile

# 11  
Old 03-18-2012
Thankyou so much, that worked perfectly.
Thanks for all the suggestions.
Much appreciated, regards
# 12  
Old 03-21-2012
Hello may I ask
I have been having trouble with user input that produces a variable to put into this NAWK command. Other words the user inputs data when prompted and that data is inserted into the NAWK.
I have been trying with the code with "$xxx" but no success, could you tell me where I am going wrong, thankyou

I have left out the rest of the script as that is running ok, it fails at this point and prints everything to the screen ignoring the variable that the user types in.
Code:
printf "enter search data "
read string

I rty the NAWK command
Code:
nawk '   /OUT/ { gsub(/\n/, "\n\t\t"); print "\t\t"$0}   /$string/' RS= FS="\n" ORS="\n\n" IGNORECASE=1 infile

Could you tell me why the variable $string is being ignored , I have tried it with quotes "$string"
thankyou

Last edited by Franklin52; 03-23-2012 at 04:56 AM.. Reason: Please use code tags for code and data samples, thank you
# 13  
Old 03-21-2012
You could define a variable and use that in the program:

Code:
nawk  -v look="$string" ' /OUT/ { gsub(/\n/, "\n\t\t"); print "\t\t"$0} $0~look' RS= FS="\n" ORS="\n\n" IGNORECASE=1 infile

Or end single quotes and put $string in double:

Code:
nawk ' /OUT/ { gsub(/\n/, "\n\t\t"); print "\t\t"$0}'"/$string/" RS= FS="\n" ORS="\n\n" IGNORECASE=1 infile

# 14  
Old 03-21-2012
Thanks for replying Chubler
For some reason it still seems to ignore the $string variable and prints out the paragraphs with the defined OUT contained in it.
I tried both methods you gave me
Code:
printf "enter search string: "
 read string
 sed '/NZDT/{N;s/\n//;}' $filename >$newfilename
 sleep 3
 nawk  -v look="$string" ' /OUT/ { gsub(/\n/, "\n\t\t"); print "\t\t"$0} $0~look'
  RS= FS="\n" ORS="\n\n" IGNORECASE=1 $newfilename

Hopefully I have defined the variable correctly in the read statement which should then fill the NAWK but I get all the paragraphs that contain 'OUT'

Last edited by Franklin52; 03-22-2012 at 04:20 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Align columns

I have a text file that I filtered using awk. I only exctracted two columns. I want those two columns to be aligned. Most of the answers I found was to use `column -t` command. I tried that but I am getting a `bash: column: command not found`. Is there another way to align columns... (1 Reply)
Discussion started by: erin00
1 Replies

2. Shell Programming and Scripting

Re align in one row using sed

Hi, Anyone can help on how to re align my data in one row using sed. test.csv "url1","abc","project url1" 2016-08-16 "url2,"microsoft","project url2" 2016-08-18 need output like this "url1","abc","project url1","2016-08-16" "url2,"microsoft","project url2","2016-08-18" Thanks in... (8 Replies)
Discussion started by: fspalero
8 Replies

3. Shell Programming and Scripting

Align input fields on one under each other

Hello again, I'm having a issue with a contact form. I want the input fields to be aligned on same row and I really dont know how to do it. I attached a image for you to understand what i am trying to do. <BR> <label for="name" class="required"> Name&nbsp;<strong... (1 Reply)
Discussion started by: galford
1 Replies

4. Shell Programming and Scripting

Align columns

Hi, I have a question on how to align columns in shellscipt. SAMPLE 2015-07-15 09:01:00.0 |TCSERVER01 |10965 2015-07-15 09:02:00.0 |TCSERVER01 |4752 2015-07-15 09:03:00.0 |TCSERVER01 |4805 2015-07-15 09:04:00.0 |TCSERVER01 |3690 2015-07-15 09:01:00.0 |TCSERVER02 |8703 2015-07-15... (1 Reply)
Discussion started by: reignangel2003
1 Replies

5. Shell Programming and Scripting

Align data of the paragraph

Hi, I need your help to align data from paragraph. It's to : - delete the lign contain NDS - align data between paragraph start to "ND=" from second "ND=" example of file: @ ABOIL; @ CEN=1/15-05-23/09 H 06 MN 18/LISTAGE CARACTERISTIQUES D'ABONNES TRAITEMENT TGLAIL ACC... (1 Reply)
Discussion started by: vremen3
1 Replies

6. Shell Programming and Scripting

Better Align--output of find command

Hi, i have sh program which search for a file in a folder structure and provides its path. This is just used to see if that file exits more that once anywhere down the folder structure. I have used find command to search & printing it output on terminal. I have attached screen shot of it.... (10 Replies)
Discussion started by: praveenkumar198
10 Replies

7. Shell Programming and Scripting

Align with printf or other method

below line is one by one print audio_play PASS boot_check FAIL ethernet_change_mac NIC_82574L PASS gps_ublox_neo FAIL storage_bonnie USB2 PASS storage_copy_big_file USB2 PASS I would like below format ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

8. Shell Programming and Scripting

Align the words

HI , I am new to shell scripting i m getting the below format like this Name FirstName Lastname ------ --------- ---------- Name1 Balaji NandaKishore Name123 Vijaya krsihna ... (5 Replies)
Discussion started by: Lucky123
5 Replies

9. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

10. UNIX for Dummies Questions & Answers

Align Text from a file.

I need to align text from a file that has columns seperated by spaces and commas. Any ideas? Text is similar to this. File Name is Test. 05/14/06 13:46:56.575 ,TEST,5,123,1234,123,12345,12,12.2,2.1,4.5,5.23 05/14/06 13:49:58.009 ,TEST,6,456,456.7,45,4.56,453,34,54.3,3.2,6.456 (9 Replies)
Discussion started by: earlepps
9 Replies
Login or Register to Ask a Question