And always say what didn't work - show the error message you get or the wrong output of the command, if it worked.
Just to say "It doesn't work!" is not really helpful.
how can i insert a string sush as "###" instead of blank lines in a file?
What exactly is a "blank line" for you?
Is it a line with no characters on it? Then this is your solution:
Or is it a line with only (optional?) whitespace on it? Then your solution is this (replace "<spc>" and "<tab>" with literal spaces/tabs):
Btw.: someone has suggested to use "tee" to change the source file in place without using an intermediate file. This is a risky technique and i would like to discourage it. It could well happen that the source is written over before it is read completely and the behaviour in case of power loss is unpredicable.
itkamaraj is spot on: i can't see if your file contains non-printable characters (such as whitespace) or not and therefore provided you with two possible solutions.
Trying only one of them without even reading (much less answering) my question is - sorry to be so blunt - negligently wasting others efforts to help you. The reader here is to put as much effort in trying to understand the given answers as the writers of same are putting into writing them up.
Furthermore:
Quote:
Originally Posted by oreka18
i do your script in my file but it doesn't work!
[...] your script:
This is definitely not "my script", because it contains a syntax error which was not there in the script i gave you and it woldn't have produced the output you mentioned, because it wouldn't have produced no output at all save for the message stating the syntax error.
If you want to succeed in writing scripts you have to be precise in what you do and what you think. Right now you gave us a sloppily defined problem, applied the solutions given to you in a sloppy way, analysed the reasons only sloppily (or not at all) and reported back in a sloppy way.
Regardless of us being able to solve your problem despite your efforts to not let us i can guarantee you that your scripts will fail badly: not because of this or that syntactical or procedural error, but because you don't show the right attitude to writing scripts (or doing sysadmin work, for that matter) correctly.
Regarding blank lines. IMO awk is best suited for this since NF catches everything, empty lines plus lines that consist of any kind of whitespace.
will remove any empty line..
Last edited by Scrutinizer; 05-10-2012 at 06:52 PM..
Hi All
Need Help
I have a file with the below format (ABC.TXT) :
®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790
HDFLJDKJSKJ|KJALKSD02|M|7378439274898
KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999
(cont......)
I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string.
Line repeating working every 3 lines using code:
sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt
I cannot seem to find... (1 Reply)
Hello,
I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance.
Contents of infile:
Test this 1...
Test this 2...
Test this 3... Test this 4... Test this... (2 Replies)
Hi,
Consider a file named "testfile"
The contents of file are as below
first line added for test
second line added for test
third line added for test
fourth line added for test
fifth line added for test (5 Replies)
Hello,
I am trying to write a script that will count the number of characters for each line in a file and all the lines that have less than 80 characters and that are ending with a period, I want it to insert a blank line after them immediately. But, for whatever reason the condition if ]] is... (3 Replies)
Hi All,
In continuation of my previous thread 'Add text at the end of line conditionally', I need to further modfiy the file after adding text at the end of the line. Now, I need to add a fixed charater string at alternate lines starting from first line using awk or sed.My file is now as below:... (10 Replies)
I need help on how I can accomplish my task. I hope someone can help me since I've researching and trying to accomplish this for hours now. Basically, I need to comment-out (or insert a # sign in the beginning of the line) a line when the line has the specific word I am searching. Example I have... (3 Replies)
All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line.
Log EXAMPLE :
MT:Exception caught
The following Numbers were affected:
1234
2345
2346
Error
java.lang.InternalError:... (3 Replies)
Hi friends,
I am looking for a line to find a particular string in my file and once found then replace with 2-3 blank lines before the string
Example:
aaa 11 bbb
1
2
3
aaa 22 bbb
4
5
6
Output (4 Replies)