awk: sort lines by count of a character or string in a line
I want to sort lines by how many times a string occurs in each line (the most times first).
I know how to do this in two passes (add a count field in the first pass then sort on it in the second pass).
However, can it be done more optimally with a single AWK command? My AWK has improved tremendously in the last few days, but I'm not there yet.
I have written a script that "raises" all files in subdirectores up the supplied path, appending a -1, -2, -3, etc to the end of the filename (before the '.' file extension if present) if there are multiple files with the same name. It leaves all of most of those sub directories empty. I want to clean up the empty directories at the end..
finds them all but I need to sort them in order of deepest first or my attempts to rmdir them will fail when a folder contains deeper empty folders.
Nope. I've got a script that moves all the regular files in subdirectories into the main directory, appending a number on the end when there are duplicate file names.
I want to clean up the remaining empty directories SAFELY (there is a chance one or more contains a special file in which case I wan't the rmdir to fail--I do not want to use -rf! ).
mindepth is being used to exclude the main directory. Specifically mindepth 1 excludes '.'.
Or you can simply add -depth to your find command and execute rmdir, ignoring eventual errors (/dev/null).
In addition, some find implementations support the -empty flag.
In addition, some find implementations (like GNU find, for instance) support the -empty option:
Quote:
-empty File is empty and is either a regular file or a directory.
I will appreciate if you help me here in this script in Solaris Enviroment.
Scenario:
i have 2 files :
1) /tmp/TRANSACTIONS_DAILY_20180730.txt:
201807300000000004
201807300000000005
201807300000000006
201807300000000007
201807300000000008
2)... (10 Replies)
I need the character count of the last line of each file in a directory, and not the total.
Now I have been doing this but unfortunately, -exec doesn't support pipes:
find sent/ -type f -exec tail -1|wc -c {} \;
If I try this:
find sent/ -type f -exec tail -1 {} \; | wc -c
It will give... (6 Replies)
Hello All,
I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form
1|121|asda|434|thesi|2012|05|24|
1|343|unit|09|best|2012|11|5|
I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Hi,
I have a file with more than 1000 lines. Most of the lines have 16 characters. I want to find out lines that have less than 14 characters (usually 12 or 13).
wc -l gives me the line count and wc -c gives me the total characters in a file. I could not get the total characters for each line.... (1 Reply)
Hi ,
I am doing some enhancements in an existing shell script. There it used the awk command in a function as below :
float_expr() {
IFS=" " command eval 'awk "
BEGIN {
result = $*
print result
exit(result == 0)
}"'
}
It calls the function float_expr to evaluate two values ,... (1 Reply)
Sample file:
This is line one,
this is another line,
this is the PRIMARY INDEX line
l ;
This is another line
The command should find the line with “PRIMARY INDEX” and remove the last character from the line preceding it (in this case , comma) and remove the first character from the line... (5 Replies)
Please check the attachment for the example.
Purpose: count how many "|" character in one line and also display the line number.
expect result:
Line 1 : there are 473 "|" characters
Line 2 : there are 473 "|" characters
I have tried to use awk to count it, it's ok when the statistic... (8 Replies)
I am parsing a nagios config, searching for a string, and then printing the line 2 lines later (the "members" string). Here's the data:
define hostgroup{
hostgroup_name chat-dev
alias chat-dev
members thisisahostname
}
define hostgroup{
... (1 Reply)
Hi folks,
I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)