Here's a streamlined awk version:
The default action in awk is print, so a pattern with no action just prints the line. The first pattern/action pair skips lines that start with "E". Since awk does an autosplit into $1, $2, ... on each input line after trimming leading and trailing whitespace (with the default delimiter /[ \t]+/), if there are only spaces, there are no fields, i.e., NF == 0 is true.
Note that after closing an action, the awk parser is in a "pattern state", so the above could be written on one line:
or
Notice in the latter that the easier condition is checked first, i.e., the regexp pattern match is only done if there are non-space characters on the line. With a huge file (or repeated execution) this means the latter should perform better (this claim is not tested).
Now I have two flat text files, I only need to choose some of the fields from both files and combine into one file, then load to a database table. Is there any way to do it?
You'll need to be a bit more descriptive with what you're trying to do here.. i.e. what lines inparticular are you going to want to pull out? Read up on the grep command. If you're looking for lines with the word "hi" in them, you'd use something like grep "hi" file1 file2 > new_file.
Dear All,
In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read.
For example, consider the extract below:
123
234
543
111... (7 Replies)
I need to identify the exact text of San Antonio Generator Running in the output my script which lands to a text file. Once SED finds the specific text, I need it to insert one line above the matched text.
Here is what I have so far that isn't working all that well for me. Any help would be... (7 Replies)
Hi,
Is there a way to find out the line number from where the data starts?
like if the data contains column header, irrespective of the text in the column header we should get the line number from which contains the column header.
I am sorry if I haven't explained the problem clearly.
... (8 Replies)
Hi All,
I am creating a text file using perl. The first record I am writing as "$line" and all the other as "\n$line". At the end the file is having N number of lines. I am using this file for MLOAD (Teradata), which is reading N+1 lines in the file and failing.I am not able to find new line... (2 Replies)
When I use vi to see what's in the file I get this:
int add1(int x) {^M return x + 1;^M}
^Mint subtract1(int x) {^M return x - 1;^M}
^Mint double_it(int x) {^M return x * 2;^M}
^Mint halve_it(int x) {^Mreturn x / 2;^M}
^Mint main() {^M int myint;^M int result;^M ... (2 Replies)
Hi All,
I have a file.txt which seems like having three lines.
wc -l file.txt
3 file.txt
In fact, once it is open in text editor, this file has four lines where the last line is empty. how can i delete this last empty line of the file.txt? I tried the codes below so far but they... (6 Replies)
Ok,
so i've been having to write to flat files lately and then making my script read information from the flat file and then work off of that.
i dont want to keep doing that because i believe it creates a mess. i like to keep my work all to one script instead of having that one script... (7 Replies)
Hello,
I need to take a random word from a flat text file with words in it seperated by spaces.
The code I am using, always gives me the first word. Can anyone please shed some light on this. Here's my code.
Thanks
echo table roof ceiling jar computer monitor keyboard carpet >... (5 Replies)
I need your help,
I want to add a text every 2nd line and also a blank line after 3 line
(In the output 2nd line is "changetype: modify" and every 4th line is blank line)
Input file format
dn: abc
orclsourceobjectdn: abcd
dn: bcd
orclsourceobjectdn: bcda
dn: cba
orclsourceobjectdn:... (7 Replies)
Hi everybody. I need help and I hope someone is willing to help me out here.
My wholesale company is currently moving to new software. The old software is running on a UNIX platform. We need to migrate data from the UNIX system, but our former software provider refuses to assist the data... (5 Replies)