I still get the space prefix chracter[s] on third line.. I used a TAB + spacebar on third line in my input.. Again trimming should work for any combination of space characters.
Here is the output of "danmero" code. Works great,, This is easier for me to understand..
Dan how would you trim spaces that could be suffixed using your approach? Even though I did not mention this requirement earlier. That is where I want to take this,, so that my code would not break even if users make common mistakes..
Here is the output of "Franklin52". You must be a mind reader too..apart from being great at scripting :-).
It meets my requirement of removing spaces at the end of line too.. I think, that could sometimes break code if users make typos with input files.
I would really appreciate if you could explain how the above command works. I am getting little dizzy with it..
Thanks in advance !..
---------- Post updated at 07:59 PM ---------- Previous update was at 07:56 PM ----------
Since suffix spaces in my input.txt file got removed,, in my previous post,, I am posting it again..
---------- Post updated at 08:17 PM ---------- Previous update was at 08:09 PM ----------
My solution will remove any leading spaces or tab char preserving the rest of the record.
On the other hand Franklin52 solution will reformat($1==$1) the record replacing FS(space and/or tab char) by default OFS(single space char).
Dan Thanks for the update,, you are right Frank's $1=$1 is removing more than one space between words, I am sure he is going to come up with a better idea :-)!
Latest, input file with requirements...
Output from "danmero's" latest code -->
Dan is it possible to trim suffix spaces at the end of the line, i.e after --> 55 ?
Can we adjust the command a little to get that perfection !?
Last edited by kchinnam; 05-03-2010 at 11:15 PM..
Reason: removed what may be a personal reference..
The only way to precisely implement a general purpose sh script to strip comments is to implement a sh language parser. In short, the goal would be to implement a sh parser in sh. Anything less would not be dependable for general purpose use. That said, for your needs (whatever they may be), perhaps an 80% solution is satisfactory 99% of the time.
If the input to the comment stripper is not constrained to some restricted format, there will be problems. The "#" is used for purposes other than to introduce a comment. And, even if it had no other use, situations like quoted strings and command substitutions would need to be taken into account.
The following posix-compliant sh script would be mangled by any naive solution.
nocomments.sh:
Note that the above sh script contains no comments, other than the shebang line (#!/bin/sh), which you may not want to strip, depending on your goal.
Verifying the validity of the script, and that the line beginning with a "#" is indeed not a comment:
Testing a proposed solution (sorry, danmero, I just picked yours because it's the latest post as I write this ; all others suffer the same shortcomings):
The comment-less (shebang excepted) script has been mutilated.
Again, the proposed solutions may be sufficient for your needs; I'm simply pointing out their unsuitability for general purpose use.
Regards,
Alister
P.S. And those are just some posix-compliant possibilities, who knows what madness awaits beyond the standard
Hello All,
I want to print data in between two lines in a file sample.txt through more or cat command on the screen. For that I am using below sed command to give the BEGIN and END text.
Content of sample.txt
server01:~ # cat /proc/mdstat
Hello this is a text message 1
Hello this is a... (5 Replies)
I searched and found "echo -n" and "printf" are solution for this, but they are not
here:
$ echo "hello" >> test
$ cat test
hello
$ echo -n "world" >> test
$ cat test
hello
world
$ echo -n " seriously?" >> test
$ cat test
hello
world seriously?
This is not successful... (15 Replies)
I cannot seem to get this to work..
I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application.
the file looks like this
this is a test
that is a test
balblblablblhblbha... (1 Reply)
So, I want to read line-by-line a text file with unknown number of files....
So:
a=1
b=1
while ; do
b=`sed -n '$ap' test`
a=`expr $a + 1`
$here do something with b etc
done
the problem is that sed does not seem to recognise the $a, even when trying
sed -n ' $a p'
So, I cannot read... (3 Replies)
Hi,
I want to filter record from a file if the records in the second column matches the data in another file. I tried the below awk command but it filters the records in the filter file. I want the opposite, to include only the records in the filter file.
I tried this:
awk -F'|'... (8 Replies)
Hello.
I am a french newbie in unix shell scripting (sorry if my english speaking is wrong).
I have a file with path and filenames in it. I want to limit the number of characters on each line and break the line if necessary. But the "break" should occur after a slash caracter "/".
Example of... (9 Replies)
Hi All,
I have a script that reads a file and echo it back to std out.
Test.txt
1aaaaaaaaaaa .
The script is ReadLine.sh
#!/bin/ksh
cat $1 | while read file
do
echo $file
done
I invoke the script as ReadLine.sh Test.txt
The output that I get is (1 Reply)
Hi,
Apologies if this has been asked before, but I searched and was not able to find an answer. It's probably a simple question to answer for those of you with some experience, though...
I have a relatively long string where tokens are separated by the colon (':') character. Let's say the... (10 Replies)
Hi!
1. I have a parameter file containing path to log files. For this example both paths are the same, one is stated directly and the second using env variables.
/oracle/admin/orcl/bdump/:atlas:trc:N
${ORACLE_BASE}/admin/${ORACLE_SID}/bdump/:${ORACLE_SID}:trc:N
2. I try to parse the path... (1 Reply)
We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)