how do i sort this list of emails using bash? [duplicate] - linux

This question already has an answer here:
Output from sort does not appear to be sorted
(1 answer)
Closed 2 years ago.
I'm trying to sort a list of emails using a bash script with code below but I'm getting the wrong output, advice
sort -t # -k1,1

You will need to add -d for dictionary order and so:
sort -r -d -t# -k1,1

Related

How to remove date from filename linux [duplicate]

This question already has answers here:
Rename multiple files while keeping the same extension on Linux
(4 answers)
Closed 3 years ago.
I have a scenario where I want to remove date from filename
Lets take an example 1 :
ABC_2019_06_12.txt
Lets take an example 2 :
ABCDEF_202012040120456.txt
using cut I cannot delete required text
how to cut to get the required below output like below
ABC.txt
ABCDEF.txt
One command which should work for all scenario which ever filename it is
My solution which I worked is to read the number of position and cut that part but I don't find it effective any other solution will be appreciated
In bash you can cut off the part starting with underscore:
$ filename=ABC_2019_06_12.txt
$ filename=${filename%%_*}
$ echo $filename
ABC

Saving lines from cat to array [duplicate]

This question already has answers here:
Creating an array from a text file in Bash
(7 answers)
Closed 6 years ago.
I'm trying to read numbers from .txt file and than store it into array so I can sort them using bubble sort.
I was trying something like that:
input=$1
readIt=`cat $1`
array=${#readIt[*]}
When I was trying to display it using echo it is displaying good, but when I'm trying to sort it, then it doesn't work.
Any help, please?
EDIT: I checked other topics, but I want to solve this problem using "cat" to understand it in easier way as beginner.
Use readarray (bash 4+)
readarray -t array < "$1"
or a loop (prior to bash 4):
while IFS= read -r line; do
array+=("$line")
done < "$1"

How to sort file names by specific part in linux? [duplicate]

This question already has answers here:
How can I sort file names by version numbers?
(7 answers)
Closed 8 years ago.
I have lots of files in my build folder and I am trying to sort them by using sort command.
The structure of the files are like that:
name - version - 'v' - build date
xxx-2.0.0-SNAPSHOT-V2014-07-10_18-01-05.log
xxx-2.0.0-SNAPSHOT-V2014-07-10_18-02-05.log
xxx-2.0.0-SNAPSHOT-V2014-07-10_18-03-05.log
xxx-2.0.0-SNAPSHOT-V2014-07-10_18-04-05.log
xxx-2.0.0-SNAPSHOT-V2014-07-10_18-05-05.log
if we assume that version string will be stay in 3 digit, sorting them is easy. What if I add different versions like 2.1 or 2.0.0.2 here ? I need a result like this:
xxx-2.1-SNAPSHOT-V2014-07-10_18-05-05.log
xxx-2.0.2-SNAPSHOT-V2014-07-10_18-04-05.log
xxx-2.0.0.2-SNAPSHOT-V2014-07-10_18-03-05.log
xxx-2.0.0.1-SNAPSHOT-V2014-07-10_18-02-05.log
xxx-2.0.-SNAPSHOT-V2014-07-10_18-01-05.log
$ cat file
xxx-2.0.2-SNAPSHOT-V2014-07-10_18-04-05.log
xxx-2.0.0.2-SNAPSHOT-V2014-07-10_18-03-05.log
xxx-2.1-SNAPSHOT-V2014-07-10_18-05-05.log
xxx-2.0.0.1-SNAPSHOT-V2014-07-10_18-02-05.log
xxx-2.0.-SNAPSHOT-V2014-07-10_18-01-05.log
$ sort -V -r -t- -k2,2 < file
xxx-2.1-SNAPSHOT-V2014-07-10_18-05-05.log
xxx-2.0.2-SNAPSHOT-V2014-07-10_18-04-05.log
xxx-2.0.0.2-SNAPSHOT-V2014-07-10_18-03-05.log
xxx-2.0.0.1-SNAPSHOT-V2014-07-10_18-02-05.log
xxx-2.0.-SNAPSHOT-V2014-07-10_18-01-05.log
Note: Some implementations of sort do not support -V option...
Explanation:
-V : Version sort
-t- : Split into columns with delimiter '-'
-k2,2: Sort by field 2 & only 2
-r : reverse sort (based on your expected output. Remove this flag, if not required.)

How to avoid the display of the 2 first line from a linux command output? [duplicate]

This question already has answers here:
What's the opposite of head? I want all but the first N lines of a file
(9 answers)
Closed 8 years ago.
I have a program that displays many line in the output
How I can make it display the all output except the first 2 lines?
easily using tail command:
tail -n+3
You could use awk
awk 'NR>2' file
In order to complete the triplet,
sed '1,2d' file

How to do the opposite of diff? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
how to show lines in common (reverse diff)?
Is there a command to do the opposite of diff? I want to compare two files if the same thing exists in both create a list of them. i am trying to figure out what entry's exist in both files.
Here is a solution that WILL NOT change the order of the lines:
fgrep -x -f file1 file2
Use the join command:
join a.txt b.txt
assuming the files are sorted; if not:
sort a.txt > sorted_a.txt; sort b.txt > sorted_b.txt; join sorted_a.txt sorted_b.txt

Resources