Issue
I have more than 4,000 text files that contain data from a fitting - different physical values derived from applying a simple model. The files have the naming convention: file_##,##_hill5.txt (where ##,## is a coordinate representation for each file). I need one particular data value as well as a portion of the filename to be printed to the same output file. Looking around the available answers to sed questions and editing for my needs, I came up with:
ls *.txt | sed -n '/^# Tau: */s///p;y/ /\n/' > results.txt
-- this command derives the value of tau, i.e. ????? from "Tau: ?????" from each text file.
The second sed command that I have:
sed -n s/.*_\([0-9]*,[0-9]*\)_.*/\1/p * > results.txt
derives the ##,## coordinate values from the filename.
The output from running each sed code on the set of files is:
3.09428
3.35559
3.75969
4.42674
5.57755
and
24,15
23,14
21,17
17,18
19,10
However, I would like the tau-value and sets of digits to be printed side-by-side; namely,
3.09428 24,15
3.35559 23,14
3.75969 21,17
4.42674 17,18
5.57755 19,10
Is this possible using a single sed command?
Solution
How can I have the iterative results from two sed commands printed on the same line of an output file?
Use paste
or other tools.
Is this possible with sed?
Not solely in sed
, no. External tools or extra preformated arguments are needed.
Answered By - KamilCuk Answer Checked By - David Marino (WPSolving Volunteer)