Hello Gurus,
This is my first ever post here. I tried looking for similar material but came up empty handed. Apologies if this is too verbose or if I'm not using the correct formatting.
I have files containing a fixed number of elements per line; separator is a single space. Each line has the number of elements and a line identifier as "prefix". For example, s_04 contains:
What I want is to cut each field in turn, and keep track of which field was cut. For example s_04.cut would contain
So far, I'm able to cut each field in turn and append it to the desired output file:
The problem is I don't know how to construct a pipe in which somehow $j is echoed/pasted/inserted after the first two fields in the output file. I'm using an awk script to generate the cut fields externally and then using cut and paste to insert it. It works but it's clunky and am looking for something more elegant and "unixy"
I would be grateful for any guidance. In case it matters, I'm working in some recent flavor of Ubuntu.
Thanks, Scrutinizer. It is an appealing one-liner, but it comes at the cost of clarity (at least to my novice eyes). I ended up saving RudiC's code as a stand-alone awk script and then piping its output to sort. Even though this is a "one-off" project and I don't foresee revisiting it again, in a few months it will be nice to be understand the "magic". ;-)
Hi All,
I having a data file which consists of 20cr records in it. The 1st column is year field which consist of year in format 200809 and fields are seperated with ^.
How do i trim it to 2008 in file and save it in a quick time as there are many records so that i can use the file for loading... (3 Replies)
Hi all,
I tried to use the paste command to paste two files with different number of lines.
e.g.
file1
A 1
B 1
C 2
D 2
file2
A 2
B 3
C 4
D 4
E 4 (2 Replies)
I have a file laid out in columns with the first two lines line being:
219 432 4567
219 432 4587
I need to create a single line command to cut the characters in the 5th column and paste them back to the first column in the same file. (Hint:Two good solutions exist, one in which you use a... (9 Replies)
I have two text files: One is a single column of numbers and the other is a space delimited text file with multiple columns. I want to paste the single column of numbers into the second column of the latter text file. How do I go about doing that? Thanks! (1 Reply)
Hi,
I have a tab-delimited txt file as below. It is part of the original file.
I want to cut the lines starting with "3" in column1 and paste them before the lines starting with "1" in column 1. So I will get
Anyone knows any simple shell scripts to do that? The original file is... (5 Replies)
I have a script in a directory and want to search the directory before like follows:
i=0
for file in ../HN_*
do
echo $file
((i+=1))
echo $i
done
Currently I get following output:
../HN_2
1
../HN_3
2 (2 Replies)
First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts.
Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea.
In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
I am having a stupid moment :-)
I have a tab-delimited file with 2 columns. I want to keep the first column as it is, but I only want the first 8 characters of the 2nd column.
Example of input file data:
---------------------------------
CATERPILLARS CW001651K.dwg... (9 Replies)
Hi there !
I have file with single column. I want to cut that column at fixed number of rows each time and paste in another file, in a way that in new file, the each cutting appear as separate columns.
I mean cutting file with one column of 10000 rows, with 100 rows each time, and in new file... (3 Replies)
Hi folks,
I need to find the following value:
First,I need to find the starting section by finding the line:
<process-type id="OC4J_RiGHTv_${SCHEMA_NAME}" module-id="OC4J">
Second,under this line I need to find the following line:
<port id="rmi" range="3765-3776"/>
And third,from this line... (4 Replies)