Sorting multiple different string in a file to a outputfile

how to sort a text file containing multiple columns in java
how do i sort records in a text file using java?
how to sort a text file alphabetically in java
how to sort numbers in a file in java
sort - t
linux sort multiple columns
linux sort text file alphabetically
java sort large text file

I am trying to sort all IPs with the same port into one output file. The issue I am having is that with the syntax I use, a lot of wrong IPs will get in the output file:

cat input.txt | grep ":80" > output.port80.txt

Content of the input.txt:

192.168.1.1:8080
192.168.1.2:80
192.168.1.3:18080
192.168.1.4:808
192.168.1.5:80
...

If you are using GNU grep, you can use:

grep -P ':80\b' input.txt > output.port80.txt

otherwise, if the file is end in :port, use this:

grep ':80$' input.txt > output.port80.txt

More exactly, if there're white spaces after :port,

grep ':80[[:space:]]*$' input.txt > output.port80.txt

With awk however, you can dealing with situations like 192.168.1.7:80THINGSafter, and remove the things after the :port:

awk '(p=index($0, ":80")) && (substr($0,p+3,1) !~ /[0-9]/){print substr($0,1,p+2)}' input.txt > output.port80.txt

How to sort data from multiple files in java, You can do this with multiple files by looping over the list of files that you need to Create reader with access to file String fileLine = fileReader. I decided to just output it. Currently I have something close to this, and I am trying to pass in a folder which has 3 different files that I want it to read through. $ sort file -o file Browse other questions tagged linux bash shell unix sorting or ask your own question. Ask Different (Apple)

Assuming that you need to have only those IPs which are ending with 80 port if this is the case then try following.

grep '.*:80$' Input_file > output_file

How To Sort A Text File In Java?, Java program to sort a text file containing records in single column or multiple columns, how to sort a text file with single column or multiple columns .. file. ArrayList<String> lines = new ArrayList<String>(); Step 6 : Write every element of ArrayList lines into output text file. Join 12,024 other subscribers. Describe the sort or merge file to be used for sorting or merging. Describe the input to be sorted or merged. If you want to process the records before you sort them, code an input procedure. Describe the output from sorting or merging. If you want to process the records after you sort or merge them, code an output procedure.

You can use awk also

$ awk -F: ' /:80$/ { print $0  } ' gerald.log
192.168.1.2:80
192.168.1.5:80

$ awk -F: ' /:80$/ { print $0 > "output." $2 ".log" } ' gerald.log

$ cat  output.80.log
192.168.1.2:80
192.168.1.5:80

$

SORT command in Linux/Unix with examples, Using the -o option is functionally the same as redirecting the output to a file. Note: Neither one has an advantage over the other. Example:The input file is the � Posted: Tue Feb 17, 2009 5:25 pm Post subject: SORTing multiple input files with different record length. Dear Friends, I have two input files one with the reord length of 130 and the other with the record length of 135.

File::Sort - Sort a file or merge sort multiple files, Where an option can take multiple values (like I , k , and pos ), values may The other modifiers behave like the corresponding options, but apply Sort file by straight string compare of each line, sending output to STDOUT. Sorting Names in a text file using java program h1. Deleting numbers in a text file, sorting the names and writing in to a new file h2. Sample data ===== 71234 RAJA 89763 KING 89877 QUEEN ===== h2.

Sort text files with multiple lines as a row, msort(1) was designed to be able to sort files with multi-line records. It has an optional gui, as well as a normal and usable-for-humans� Sorting the chunks is also pretty straightforwards, as i use C#'s Array.Sort because it does the job just fine thank you very much. C# purists won't like my use of GC.Collect here, but it was mainly just to keep things under the 50mb limit.

Sort lines of a text file, txt in alphabetical order using the second column. To check if a file is already sorted, use sort with the -c option. This option also reports the first unsorted line:. Re: sort or merge three files to one output file. by Robert Sample » Wed May 09, 2012 5:58 pm You place the SORT statement in your JCL after the //SYSIN DD * and the fact that you did not do so is what the computer message is telling you.

Comments
  • add a word boundary to your regex pattern: grep ":80\>" input.txt > output.port80.txt
  • IF you just want port 80 add a $ to indicate end, e.g. grep ':80$' < input > output PS, don't cat input | that is a UUOc (Unnecessary Use Of cat). Either use redirection or just grep the first file, e.g. grep ':80$' input > output