Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with output after separating script lines 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

whenever a certain line within a script becomes too long I'm trying to use \ to separate the specific line ...

e.G.

Code:
if [something -eq something ];
then
  cat /123/abc/dljsa/blabla/loooong_directory/1.pdf | grep test | awk '{print $1}' > /123.log
fi

becomes

Code:
if [something -eq something ];
then
  cat /123/abc/dljsa/blabla/loooong_directory/1.pdf \
   | grep test | awk '{print $1}' > /123.log
fi

So far so good, but quite often it happens, that I need to separate the line somewhere within an echo command and if I do so all the blanks at the beginning of the second line are being printed, completely ruining the output format.

Here's an example:

Code:
if [something -eq something ];
then
  echo "Something veeeeeeeeery long it is \
   what I want to say here"
fi

The output looks something like this:

Code:
Something veeeeeeeeery long is is    what I want to say here

How can I solve this issue without having to remove the blanks at the beginning of each line between the "then" and "fi" ?

Regards,
Thomas
 
TSch,

There's probably a better way, but you could pipe it to sed and replace the extra spaces.

echo "Something veeeeeeeeery long it is \
what I want to say here" | sed 's/ */ /g'

Hope that helps!

John
 
if [something -eq something ];
then
echo "Something veeeeeeeeery long it is \
what I want to say here"
fi

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You could also use multiple echo statements, combined with whatever method your shell/OS supports to prevent a carriage return at the end of the first one.

Code:
        echo "something veeeeeeeeeeery long it is \c"
        echo "that I want to say here."

        echo -n "something veeeeeeeeeeery long it is "
        echo "that I want to say here."

        printf "something veeeeeeeeeeery long it is "
        echo "that I want to say here."



Annihilannic.
 
Hi everyone,

thanks a lot for all the input !

@johngiggs: Interesting approach. Gotta give it a thought whether this would make the script look more complicated or not ... :)

@PHV: That's what I'd like to avoid ;-) Separating certain lines is supposed to improve the readability of the script.

@Annihilannic: That looks quite promising. I think I'll give it a try. :)

Best Regards,
Thomas
 
if [something -eq something ];
then
cat <<-EOF
<Tab>Something veeeeeeeeery long it is
<Tab>what I want to say here
<Tab>EOF
fi

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I second PHV's post. The nice thing about it is you can just type your multiple lines, or paragraph, the way you want it to look, but still indent it for readability in the script. The dash "-" before the "EOF" will cause it to remove the leading whitespace, so it will left justify the paragraph for you.

I'll "star" you PHV. [bigsmile]

 
I think you are over processing it.
set each line to a var = echo line | wc -w
You then know if you need to split the line
if you need to split it split it with cut into two var's
sline=echo line | cut -c 1-32
eline= echo line | cut -c 33-$[var}
echo "$sline \\ "
echo " $eline"


or something such
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top