Tag Archives: Input File

Output block of lines in a file based on grep result

By mnassiri

Hi I would appreciate your help with this.
I have a output file from a command. It is broken based on initial of the users. Exmaple of iitials MN & SS. Under each section there is information pertaining to the user however each section can have different number of lines. MY challenge is to
Grep for a particular initials ( Example MN ) and print all the lines under this initial
and put them in to a new file. The problem is that uder each initial there could be any number of lines. So the number of lines per initial is not fixed. How can I do this? I put sample of input and output files.

Input File name >> myfile.txt
Content of the file

MN
11
22
33

SS
11
22
33
44

MN
44
55

SS
55
66
77
OUTPUT File >> Should look like this

MN
11
22
33

MN
44
55

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Remove new line character and add space to convert into fixed width file

By Amrutha24

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file.

If the length is less than the max length, the spaces should be appended before the new line character of that record.

Code:


Input File:
123
12345
1234

Output file:
123
12345
1234

Here the max record length is 5


Source: FULL ARTICLE at The UNIX and Linux Forums