removing newlines after a certain word.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing newlines after a certain word.
# 1  
Old 11-17-2011
CPU & Memory removing newlines after a certain word.

Hello! This is my first post here.

I have a file with text like:
Code:
A</title>
B
C</title>
D

I need to format it to:
Code:
AB
CD

I am trying to use sed:
Code:
sed 's/<//title>\n/ /g' file > newfile

to delete </title> and the newline character, but the file is unchanged because there are apparently no instances of that
I also looked into: tr -d '</title>\n'
but no luck. I can tell it is whatever is between </title> and the newline that is causing my trouble... Any help would be appreciated!!!
-Joe

Last edited by Scott; 11-17-2011 at 09:51 PM.. Reason: Added code tags
# 2  
Old 11-17-2011
Code:
awk -F \< '{printf /title/?RS $1:$1}' infile

# 3  
Old 11-17-2011
Hi, and welcome Smilie

You almost had it.
Code:
$ sed 'N;s#</title>\n##' file1
AB
CD

Or, more accurately:
Code:
$ sed '/<\/title/{N;s#</title>\n##;}' file1
AB
CD

# 4  
Old 11-17-2011
Thank you!

Thank you so much!
Just what I was looking for. I am processing a bunch of twitter hash-tags and their corresponding times in a bash script.

-Joe
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

2. Shell Programming and Scripting

Removing hyphen from beginning and end of a word only.

It is very simple to remove a hyphen from a word anywhere in that word using a simple sed command (sed -i 's/-//g' filename), but I am not able to figure out how to do this: For example, apple -orange tree pipe- banana-shake dupe- What my output should look like: apple orange tree... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. UNIX for Dummies Questions & Answers

removing newlines without changing RS in BEGIN

Using awk, is there a way to remove newlines in strings that don't contain 1_ at the beginning, but without setting RS="1_" in the BEGIN section and without using a END section as well? input: 1_this is line 1 aaaaaaaa bbbb 1_this is line 2 cccc 1_this is line 3 dddddddddddddd... (7 Replies)
Discussion started by: lucasvs
7 Replies

4. Shell Programming and Scripting

problem removing a word from a file in vi

lets say i have a file named ex1 which contain an essay. (a) delete the word "benefit" from the file (b) delete the last 6 characters on each line for the first problem i entered :g/benefit/d but it deletes the whole line please help (3 Replies)
Discussion started by: koricha
3 Replies

5. Shell Programming and Scripting

removing a word in a multiple file starting at the dot extension

hi I would like to ask if someone knows a command or a script on how to rename a multiple file in the directory starting at the end of the filename or at the .extension( i would like to remove the last 11 character before the extension) for example Below is the result of my command ls inside... (5 Replies)
Discussion started by: jao_madn
5 Replies

6. Shell Programming and Scripting

Removing the 1st character of the word in perl

Hi All, In one of the sections in my perl script, I need to remove the 1st character of a word and store in an array.The details are , The original script was , if ( ! defined $inq{$node}{"dmx"} ) { print "INFO: Collecting inq disk information for DMX array on $node.\n"; ... (2 Replies)
Discussion started by: abhilash.pa
2 Replies

7. Shell Programming and Scripting

Removing inserted newlines from a fileld of fixed width file.

Hi champs! I have a fixed width file in which the records appear like this 11111 <fixed spaces such as 6> description for 11111 <fixed spaces such as 6> some more field to the record of 11111 22222 <fixed spaces such as 6> description for 22222 <fixed spaces such as 6> some more field to the... (8 Replies)
Discussion started by: enigma_1
8 Replies

8. Shell Programming and Scripting

Vi - removing last word

Hi All, I want to remove last word from a line using Vi. Do we have any vi command for that. line : ss dd ff gg i have to run some vi command which can delete gg from the line Thanks, Ravi Sadani (4 Replies)
Discussion started by: ravi.sadani19
4 Replies

9. UNIX for Dummies Questions & Answers

Removing a specific word from a created list

I am working on a script that prompts a user name and creates a list in a username.dat file. Furthermore, I have created a sorted_username.dat file. My question is this: My script uses the word "finished" != finished to break the while loop. How can I avoid having the word "finished" show up in... (5 Replies)
Discussion started by: erest8
5 Replies

10. Programming

removing first bit from the word

Hello, I have a code like this : pstSimPOIInfo.ppcName = realloc(pstSimPOIInfo.ppcName, (usLen+strlen(CountryName)+4)); memset(pstSimPOIInfo.ppcName, 0, (usLen+strlen(CountryName)+4)); strncpy((char *)pstSimPOIInfo.ppcName, CityName, strlen(CityName)) strcat(pstSimPOIInfo.ppcName, ",");... (3 Replies)
Discussion started by: jazz
3 Replies
Login or Register to Ask a Question