I have a simple table like this:
======= ========= ===========
header header1 header2
======= ========= ===========
line1 line1a line1b
line2 line2a line2b
line3 line3a line3b
line4 line4a line4b
line5 line5a line5b
======= ========= ===========
But the table is getting pretty long, so I'm wondering whether its possible to get the headers to repeat at the bottom. Doing simply the following does not work:
======= ========= ===========
header header1 header2
======= ========= ===========
line1 line1a line1b
line2 line2a line2b
line3 line3a line3b
line4 line4a line4b
line5 line5a line5b
======= ========= ===========
header header1 header2
======= ========= ===========
Related
I am using
$ grep -cf keyword_file Folder1/*
to generate a count of how many lines, in files housed within Folder1, match a keyword from the keyword_file.
this generates an aggregate count total such as
file1: 7
file2: 4
file3: 9
my problem:
I would like the output to be in the form below
first_keyword
file1: 5
file2: 0
file3: 5
second_keyword
file1: 0
file2: 3
file3: 1
third_keyword
file1: 2
file2: 1
file3: 3
so that I can see how many times each individual keyword was present in a line of each file.
How do I achieve this?
===== added detail ====
keyword_file is at Documents/script_pad/keyword_file
Folder1 is at Documents/script_pad/Folder1
what worked for me was
creating a file "Documents/script_pad/loop2" containing
#!/bin/bash
cat Documents/script_pad/keyword_file | while read line
do
echo $line; grep -c $line Documents/script_pad/Folder1/*
done
which when run resulted in
$ bash Documents/script_pad/loop2
first_keyword
Documents/script_pad/Folder1/file1:5
Documents/script_pad/Folder1/file2:0
Documents/script_pad/Folder1/file3:5
second_keyword
Documents/script_pad/Folder1/file1:0
Documents/script_pad/Folder1/file2:3
Documents/script_pad/Folder1/file3:1
third_keyword
Documents/script_pad/Folder1/file1:2
Documents/script_pad/Folder1/file2:1
Documents/script_pad/Folder1/file3:3
I have a text file that has some data such as
aaaa:1.0
bbbb:1.1
cccc:1.3
I want to covert this into an excel sheet using bash/perl
The desired output is something like this
header1 header2
aaaa 1.0
bbbb 1.1
cccc 1.3
what i have tried so far is
(echo "header1;header2" ; cat a.txt) | sed 's/:/\t/g' > a.csv
but this does not seem to work.
also i want to export this text file into an excel sheet.
$ echo -e "header1\theader2"; cat file | tr : '\t' # > file.csv
header1 header2
aaaa 1.0
bbbb 1.1
cccc 1.3
or:
$ cat <(echo "header1:header2") file | tr : '\t' # > file.csv
header1 header2
aaaa 1.0
bbbb 1.1
cccc 1.3
Uncomment the > file.csv to actually write to a file.
I want to merge specific line
Input :
AAA
BBB
CCC
DDD
EEE
AAA
BBB
DDD
CCC
EEE
Output Should be
AAA
BBB
CCC DDD
EEE
AAA
BBB
DDD
CCC EEE
I want to search CCC and merge next line with it.
I have tried with awk command but didn't get success
Use awk patterns, if the line matches /CCC/ then print the line with a space at the end and go on to the next line. Otherwise (1), print the line.
awk '/CCC/ { printf("%s ", $0); next } 1' file
Using sed:
sed '/CCC/ { N; s/\n/ / }' file
Using awk:
awk '{ ORS=(/CCC/ ? FS : RS) }1' file
This question already has answers here:
vim command to restructure/force text to 80 columns
(6 answers)
Closed 9 years ago.
I want to know what is the best practice to format selected text, such that each column does not exceed N characters.
For example I had this text at the begging (Note the text doesn't exceed 80 columns):
aaaaaaa aaaaa aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa
And then suddenly I had to change the first line and and text like:
BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB
Such the text will become similar to this:
aaaaaaa aaaaa BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa
So what is the easiest way to format the text to kind force the limit on columns up to 80 characters?
P.S
I don't wan't to format every line manually.
See here.
Basically, :set tw=80, then use the gq command to reformat preexisting text. To auto-wrap the entire file, go to the first line and type gqG (note capital G).
See this question.
Set textwidth to 80, move to the start of the file (can be done with
Ctrl-Home or gg), and type gqG.
gqG formats the text starting from the current position and to the end
of the file. It will automatically join consecutive lines when
possible. You can place a blank line between two lines if you don't
want those two to be joined together.
A file contains ID, Name and other columns. I want to insert a row containing name with details before a specific ID. Then ID column should be updated with proper ID sequence.
Example
Sample File content:
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 XXX ...
5 YYY ...
6 ZZZ ...
Footer
I want to insert MMM ... before ID #4 i.e. before a row 4 XXX ...
Desired output:
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM ...
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer
I could do proper insert using following command but not sure how to update ID column with proper numbering.
sed '/^\s*4/ i 4 MMM ...' file
It would be appreciable if you could help me solve this problem.
One option can be:
awk '/^4/ {print ++i, "MMM"} /^[0-9]/ {$1=++i} 1' file
Explanation
/^4/ {print ++i, "MMM"} on line starting with 4, print MMM with an incremental value.
/^[0-9]/ {$1=++i} on lines starting with number, set first field to an incremental value.
1 print line
Test
$ awk '/^4/ {print ++i, "MMM"} /^[0-9]/ {$1=++i} 1' file
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer
$ awk '/^4 /{print "4 MMM ..."; inc=1} /^[[:digit:]]/{$1+=inc} 1' file
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM ...
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer