ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
My apologies for not being more clear in my initial question. In my first example, imagine a text file containing:
TTITLE1=There has go
TTITLE1=t to be a better way.
I want my script to parse this as "There has got to be a better way."
In my second example, imagine my text file contains:
TTITLE2=You shook me all night
TTITLE2=long.
Here, I'd want to parse it as "You shook me all night long."
The problem is that, depending on how I parse the file, I either end up with:
There has go t to be a better way. #unwanted space in "got"
You shook me all night long.
or
There has got to be a better way.
You shook me allnight long. # No space between "all" and "night"
Regardless of whether I use cut, sed, or awk, lines that end with a space aren't beiing handled correctly. Here's the script I'm using, where $1 is the file being read:
#!/bin/bash
#
titlenum=0
while [ -n "$(grep "TTITLE$titlenum=" $1)" ]
do
tan=$(grep "TTITLE$titlenum=" $1)
title=$(echo ${tan//"TTITLE$titlenum="/} | awk '{print $0}')
echo $title >> trackfile.txt
let titlenum=titlenum+1
done
In this case, I get the following:
There has got to be a better way.
You shook me allnight long. # No space between "all" and "night"
How do I modify my script so that it properly wraps text into a single line regardless of whether or not there's a space at the end of a line?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.