moonalley
moonalley

Reputation: 1

Shell script to append to very long lines

In the very long line sample below how can I append "***" to end of line?

Tried using "$" in sed but replacement occurs not at end of line but near the end just after column 350. See "***" below.

tail -n+2 filename.dat | sed s/"$"/"***"/

[email protected]|111150151744782|99149327|NONM|20110325|20110605|TE201107E||ESOK1A||2002|2003A|2004A|2005|2007|2008|2009|2010|2011|2012|2014A|2016|2017A|2018|2019|2020|2021A|3001|3002|4001A|4002|4003|4004|4005A|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||8A12329A***833493A9C52EF5D66419ED5|016|zzzzzz|41606299952

Upvotes: 0

Views: 281

Answers (2)

kurumi
kurumi

Reputation: 25609

There are other ways to do appending. Appending is basically just attaching something to an already existing string. "Substitution" is not necessary. Just printing what you want out at the end is good enough.

shell:

   $ var=$(tail -n+2 filename.dat )
   $ echo "${var}***"

awk:

$ tail -n+2 filename.dat | awk '{print $0"***"}'

Ruby(1.9+)

$ ruby -ne 'puts $_.chomp+"***"' file

Upvotes: 0

dheerosaur
dheerosaur

Reputation: 15172

Try this: sed 's/$/*/g'

(I am using bash on Ubuntu)

Upvotes: 4

Related Questions