Operating System - HP-UX
1829328 Members
1529 Online
109989 Solutions
New Discussion

Re: Converting backslash lines to long lines...

 
SOLVED
Go to solution
Jim Krol
Advisor

Converting backslash lines to long lines...

Our hanfs.sh files use backslashes in the XFS lines for readability/neatness. I need a way to "remove" the backslashes and recombine the line to it's full length for use by a script. My script needs to see the full XFS line, not three separate ones as it would with "read -p".
7 REPLIES 7
RAC_1
Honored Contributor

Re: Converting backslash lines to long lines...

cat file|tr "\\" ""

Anil
There is no substitute to HARDWORK
Sridhar Bhaskarla
Honored Contributor

Re: Converting backslash lines to long lines...

Hi,

Try this

sed 'N;s/\\\n//;N;s/\\\n//' your_file > new_file

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Converting backslash lines to long lines...

Hmm.. The above may not work if there are space or tabs after the last \. Try this

sed 'N;s/\\[ ]*\n//;N;s/\\[ ]*\n//' text

[] is []

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Jim Krol
Advisor

Re: Converting backslash lines to long lines...

Lines in question are... (note the quotes)

XFS[0]="-o async,root=x,\
access=a:b:c \
/fileshare"

want

XFS[0]="-o async,root=x,access=a:b:c /fileshare"
Sridhar Bhaskarla
Honored Contributor

Re: Converting backslash lines to long lines...

Ted,

Doesn't it work?.

$cat text
XFS[0]="-o async,root=x,\
access=a:b:c \
/fileshare"
$sed 'N;s/\\[ ]*\n//;N;s/\\[ ]*\n//' text
XFS[0]="-o async,root=x,access=a:b:c /fileshare"

Note that you have to type [] in the place of [ ] as the message gets clobbered here.

-Sri

PS: No more further points for me please.
You may be disappointed if you fail, but you are doomed if you don't try
curt larson_1
Honored Contributor

Re: Converting backslash lines to long lines...

instead of read -p how about using read -r.
In -r raw mode, \ at the end of a line does not signify line continuation.
Tor-Arne Nostdal
Trusted Contributor

Re: Converting backslash lines to long lines...

Perhaps something like this can help you:
#!/bin/sh
# Scriptname: catx
LS="XFS"
NEW_LINE=""
while read LINE
do
echo "$LINE" | grep -q "^$LS"
[[ "$?" = "0" ]] && {
NEW_LINE="$(echo "$LINE"|tr -d '\\'|tr -d '\012')"
print "$NEW_LINE"
} || {
NEW_LINE="${NEW_LINE}${LINE}"
}
done

I've used it for listing our /etc/exports, but then I used LS="/"

Usage:
cat file | catx

/Tor-Arne
I'm trying to become President of the state I'm in...