Sponsored Content
Operating Systems Linux Remove newline in middle of string Post 302777419 by Yoda on Friday 8th of March 2013 12:36:53 AM
Old 03-08-2013
Explanation:
Code:
awk '
/^>/ {                                  # If current record starts with > ( /^</ )
        $0 = (NR > 1 ? RS $0 : $0)      # If current record number is greater 1 (NR > 1) set it to newline followed by current record (RS $0)
        ORS = RS                        # Set Output Record Separator to Record Separator (ORS = RS) [ RS is newline by default ]
}

! />/ {                                 # If current record does not contains pattern > ( !/>/ )
        ORS = ""                        # Set Output Record Separator to "" (ORS = "")
}

END {                                   # END Block
        printf "\n"                     # Print newline
} 1                                     # 1 == true, so print current record
' file

Note: ORS, RS, NR are special variables in awk. Please check the awk manual pages for further reference. I hope this helps.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

add a string in the middle of the file

i want to add a string in a very top of a file without using VI or SED or AWK this is what ive done: (echo '0a'; echo 'LINE OF TEXT'; echo '.'; echo 'wq') | ed -s myfile to add astrng right in the middle i could have count the lines of the file and just chenge the address. ... (6 Replies)
Discussion started by: ciroredz
6 Replies

2. Shell Programming and Scripting

stripping certain characters in at the middle of a string

I am trying to strip out certain characters from a string on both (left & right) sides. For example, line=see@hear|touch, i only want to echo the "hear" part. Well i have tried this approach: line=see@hear|touch templine=${line#*@} #removed "see@" echo ${templine%%\|*} #removed... (4 Replies)
Discussion started by: mcoblefias
4 Replies

3. Shell Programming and Scripting

how to remove all tabs and newline (\n)

how to remove all tabs and newline (\n) from the exicting file (2 Replies)
Discussion started by: pvr_satya
2 Replies

4. UNIX for Dummies Questions & Answers

Add string to middle of a file

Hi, I want to write a script that takes a file and a string as params and adds the string to the middle line of the file. Also, I want to output the results back to the original file passed without using temp files. I am very much new to UNIX so this is all a little like black magic to me at... (15 Replies)
Discussion started by: Chiefos
15 Replies

5. UNIX for Dummies Questions & Answers

Is it possible to grep with a newline in the middle of an expression?

I'm hoping that there is a way to do this. I'm sure I won't be able to get the answer I need on the deadline I need it...but at least I'll learn how to solve this problem. I have a file that looks like this: (00:14:25\$ head -27 QNHDSPACEDVR Name: PollDhctAVFSInfo 00:0F:21:4B:00:6A Name:... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

6. UNIX for Dummies Questions & Answers

Splitting a string and putting another string in the middle?

Hello all! I'm trying to put together a small script that will take in a file name and attach a datestamp to the end of it (but before the file type extension). To illustrate... Before: filename.txt anotherfilename.txt After: filename_20090724.txt anotherfilename_20090724.txt ... (7 Replies)
Discussion started by: jisoo411
7 Replies

7. Shell Programming and Scripting

remove newline between two string with sed command in unix shellscript

I have a file (test.dat) which contains data like this 459|199811047|a |b |shan kar|ooty| 460|199811047|a |bv |gur u|cbe| but I need it like: 459|199811047|a |b |shankar|ooty| 460|199811047|a |b |guru|cbe| While reading the data from this file, I don't want to remove newline from the end of... (4 Replies)
Discussion started by: jcrshankar
4 Replies

8. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

9. UNIX for Dummies Questions & Answers

Map a string in a the middle of a record

Hi Folks! I hope you can help me figure this out. I need to print a record which contains the contents of a config file. The contents of the config file should be found within the 21st and the 30th position of the fixed width reference file. Config File: aaaa bbbb cccc Reference... (3 Replies)
Discussion started by: kokoro
3 Replies

10. UNIX for Dummies Questions & Answers

Using sed to remove spaces from middle of the line

Hi, I need to correct href portion of the lines to edit out spaces from the line starting with position "<a href=" and ending at "target=" Below are 2 examples of extra space added by the server: <td width=251 colspan=9 rowspan=22> <font size=2 face="courier"><tt><style>{font:7pt Courier ... (4 Replies)
Discussion started by: friedmi
4 Replies
Mail::SPF::v2::Record(3)				User Contributed Perl Documentation				  Mail::SPF::v2::Record(3)

NAME
Mail::SPF::v2::Record - Sender ID ("spf2.0") record class SYNOPSIS
See Mail::SPF::Record. DESCRIPTION
An object of class Mail::SPF::v2::Record represents a Sender ID ("spf2.0") record. Constructors The following constructors are provided: new(%options): returns Mail::SPF::v2::Record Creates a new Sender ID ("spf2.0") record object. %options is a list of key/value pairs representing any of the following options: text terms global_mods See "new" in Mail::SPF::Record. scopes Required. See "new" in Mail::SPF::Record. The 'mfrom' and 'pra' scopes are supported. There is no default. new_from_string($text, %options): returns Mail::SPF::v2::Record; throws Mail::SPF::ENothingToParse, Mail::SPF::EInvalidRecordVersion, Mail::SPF::ESyntaxError Creates a new Sender ID ("spf2.0") record object by parsing the string and any options given. Class methods The following class methods are provided: version_tag_pattern: returns Regexp Returns a regular expression that matches a version tag of 'spf2.0/' plus a comma-separated list of any of the 'mfrom' and 'pra' scopes. The following are valid version tags: spf2.0/mfrom spf2.0/pra spf2.0/mfrom,pra spf2.0/pra,mfrom default_qualifier results_by_qualifier See "Class methods" in Mail::SPF::Record. Instance methods The following instance methods are provided: text scopes terms global_mods global_mod stringify eval See "Instance methods" in Mail::SPF::Record. version_tag: returns string Returns 'spf2.0/' plus a comma-separated list of the scopes of the record. See "version_tag_pattern" for a list of possible return values. SEE ALSO
Mail::SPF, Mail::SPF::Record, Mail::SPF::Term, Mail::SPF::Mech, Mail::SPF::Mod <http://tools.ietf.org/html/rfc4408> For availability, support, and license information, see the README file included with Mail::SPF. AUTHORS
Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> perl v5.16.2 2013-08-25 Mail::SPF::v2::Record(3)
All times are GMT -4. The time now is 04:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy