03-07-2009
replace the first field with a counter in awk
concat the files together, and replace the first field with a counter in awk, something like:
#!/usr/bin/ksh
for file in file1.txt file2.txt file3.txt;do
cat $file >> file.new
done
awk -F\| '
BEGIN {
OFS="|"
}
{
$1=NR
print
}
' file.new
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a set of files of multi-line records with the records separated by a blank line. I needed to add a record number to the front of each line followed by a colon and did the following:
awk 'BEGIN {FS = "\n"; RS = ""}{for (i=1; i<=NF; i++)print NR,":",$i}' ~/Desktop/data98-1-25.txt >... (3 Replies)
Discussion started by: RacerX
3 Replies
2. Shell Programming and Scripting
hello experts,
I need a sed command that remove last 10 characters of a line start from 3rd line.
any suggestions?
Thanks you (7 Replies)
Discussion started by: minifish
7 Replies
3. Shell Programming and Scripting
I have a simple text file.
I want to number each line in that file .
for example:
My text file is
unix
my file
test
My output should be
1 unix
2 my file
3 test (5 Replies)
Discussion started by: pitagi
5 Replies
4. UNIX for Advanced & Expert Users
Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line.
So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4... (2 Replies)
Discussion started by: Vryali
2 Replies
5. Shell Programming and Scripting
Hi guys,
got a problem here with sed on the command line.
If i have a string as below:
online xx:wer:xcv: sdf:/asdf/http:https-asdfd
How can i match the pattern "http:" and replace the start of the string to the pattern with null?
I tried the following but it doesn't work:
... (3 Replies)
Discussion started by: DrivesMeCrazy
3 Replies
6. Shell Programming and Scripting
Hello,
I am trying to write a shell script that will create a gnuplot file.
My main problem is that I have a data file with two columns:
1.05929120E+09 5.0000701214792
1.05930096E+09 5.00006386985764
1.05930584E+09 5.00019465404908
1.05931072E+09 5.00031960589719
... (2 Replies)
Discussion started by: pau
2 Replies
7. Shell Programming and Scripting
Hi,
I want to do the following:
Extract some lines from different files and copy them into one file, with the first column being the line number. I do this with
cat file1 file2 file3 |grep 'xxx' |nl > output.file
Works fine. But if I want to add data of interest from a fourth file to the... (2 Replies)
Discussion started by: paracetamol
2 Replies
8. Shell Programming and Scripting
Hello fellow awkers and seders:
need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows:
echo $testvar
===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Discussion started by: ux4me
1 Replies
9. Shell Programming and Scripting
The awk below produces an output with the original header and only the matching lines (which is good), but the output where the original line numbering in the match found on is used. I can not figure out how to sequentially number the output instead of using the original.
I did try to add... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. Shell Programming and Scripting
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
LEARN ABOUT LINUX
shtool-table
SHTOOL-TABLE.TMP(1) GNU Portable Shell Tool SHTOOL-TABLE.TMP(1)
NAME
shtool-table - GNU shtool pretty-print a field-separated list
SYNOPSIS
shtool table [-F|--field-sep sep] [-w|--width width] [-c|--columns cols] [-s|--strip strip] strsepstr...
DESCRIPTION
This pretty-prints a list of strings as a table.
OPTIONS
The following command line options are available.
-F, --field-sep sep
Separate columns using sep. Default is ":".
-w, --width width
Width of each column. Default is 15 characters.
-c, --columns cols
Number of columns. Default is 3.
-s, --strip strip
Strip off any characters past strip. Default is 79.
EXAMPLE
# shell script
shtool table -F , -w 5 -c 4 "1,2,3,4,5,6,7,8,9,10,11,12"
HISTORY
The GNU shtool table command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 1999 for GNU shtool.
SEE ALSO
shtool(1), tr(1), fmt(1), sh(1), awk(1), sed(1).
18-Jul-2008 shtool 2.0.8 SHTOOL-TABLE.TMP(1)