remove ] followed by newline in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove ] followed by newline in bash
# 1  
Old 12-15-2011
remove ] followed by newline in bash

I need to remove ] followed by newline character to convert lines like:

line1]
line2

into:

line1line2
# 2  
Old 12-15-2011
If you've got BASH you've got perl, so:
Code:
perl -i.bak -p -e 's/]\n//' FILE

# 3  
Old 12-15-2011
using sed,
Code:
sed ':a;N;$!ba;s_]\n__g' <filename>


Last edited by Franklin52; 12-15-2011 at 03:26 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 12-15-2011
one more ..
Code:
$ sed  'N;s/]\n[ \t]*//' infile
line1line2

# 5  
Old 12-15-2011
If you really need to handle using bash/ksh builtin properties, then
Code:
while read line
do
        case "$line" in
                *])  len=${#line}
                     ((len-=1))
                    line=${line:0:$len}
                    echo -n $line
                    ;;
                *) echo "$line" ;;
        esac
done <<EOF
line]
line2
line3
line4 here]
line5
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Remove newline char from variable

I have a file ABC.DAT with 2 columns avaialble Data format : XYZ!$#$!120 XXZ!$#$!1000 YYZ!$#$!104 While running the following code : FILE_COUNTER=1; RECORD_CN_FILE_COUNT=$((`wc -l ABC.DAT| cut -f1 -d' '`)); while do FILE_NAME=`cat ABC.DAT.DAT| head -$FILE_COUNTER |tail -1 | awk -F... (1 Reply)
Discussion started by: Nikhil Gautam
1 Replies

3. Linux

Remove newline in middle of string

my file input is with tab as delimiter, and in every line, there would be a skip of line with an unexcepted newline breaker. I'd like to remove this \n and put the information in the same line. INPUT a1 b1b2 c1 c2 d1 a2 b3 c3 d4 OUTPUT a1 b1b2 c1c2 ... (9 Replies)
Discussion started by: kinkichin
9 Replies

4. Shell Programming and Scripting

Remove newline character between two delimiters

hi i am having delimited .dat file having content like below. test.dat(5 line of records) ====== PT2~Stag~Pt2 Stag Test. Updated~PT2 S T~Area~~UNCEF R20~~2012-05-24 ~2014-05-24~~ PT2~Stag y~Pt2 Stag Test. Updated~PT2 S T~Area~METR~~~2012-05-24~2014-05-24~~test PT2~Pt2 Stag Test~~PT2 S... (4 Replies)
Discussion started by: sushine11
4 Replies

5. UNIX for Dummies Questions & Answers

formatting data to remove newline

Hi All, I have raw data in the format :- -------------------------------------------------------------------- NUT070 3 ./opc.sh SQLSCRIPT &SID sysdate.sql 20120105 NUW004 3 ./opc.sh SQLSCRIPT &SID sab_supp.sql UNUW032 3 ./opc.sh SQLSCRIPT &SID sab_unsupp.sql... (3 Replies)
Discussion started by: subhotech
3 Replies

6. UNIX for Dummies Questions & Answers

Remove newline & space

Can someone help me on this. I have a file that has a long line just like below. The long line keeps on being truncated to the next line (new line + space) for some reason. Basically, I just need to remove this problem. Hope somebody can help! Thanks! INPUT FILE: structuralObjectClass:... (4 Replies)
Discussion started by: Orbix
4 Replies

7. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

8. Shell Programming and Scripting

SED: how to remove newline after pattern?

Hi, I have the following XML not well-indented code: <hallo >this is a line </hallo> So I need to remove the newline. This syntax finds what I need to correct, but I don't know how to remove the newline after my pattern: sed 's/<.*$/&/' How can I subtract the newline after my... (1 Reply)
Discussion started by: nico.ben
1 Replies

9. 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

10. Shell Programming and Scripting

remove trailing newline characters

Hello , I have the folowing scenario : I have a text file as follows : (say name.txt) ABC DEF XYZ And I have one more xml file as follows : (say somexml.xml) <Name>ABC</Name> <Age>12</Age> <Class>D</Class> <Name>XYZ</Name> <Age>12</Age> <Class>D</Class> <Name>DEF</Name>... (7 Replies)
Discussion started by: shweta_d
7 Replies
Login or Register to Ask a Question