Script to select the rows from the feed file based on the input value provided

Hi Folks,

I have the below feed file named abc1.txt in which you can see there is a title and below is the respective values in the rows and it is completely pipe delimited file ,.

ABC_ID|AMOUNT|ABC_DATE|ABC_CODE|ABD_ID|ABDE_ID|ABEFF_DATE|ABAL_AMOUNT|ab_ON|AB_ODE|TY_CODE|RITY_TE|CR_OKER|SYS_FLAG|CRT_MENT|ADM_ID|ERG_ID|ASH_ADE
0|0.00|24-Jun-14|SSRD|1677|82588|20-Mar-14|100004.00|0|Serest|TRRS|24-Mar-19||true|Receive|861|0|3862880
1|0.00|24-Sep-14|SRSD|1477|85288|20-Mar-14|100003.00|0|Serest|TYRS|24-Mar-19||true|Receive|831|0|3828680
2|0.00|24-Dec-14|HHSD|1777|82858|20-Mar-14|100006.00|0|Serest|UIRS|24-Mar-19||true|Receive|811|0|3862880
2|0.00|24-Dec-14|ESJD|1877|82885|20-Mar-14|100009.00|0|Serest|OPRS|24-Mar-19||true|Receive|861|0|3682880

now this feed files is been generated regularly by a process and is being kept at unix box at the following location /usr/cft/str so finally the file is at /usr/cft/str/abc1.txt
now from the right side you can see there is a column named ADM_ID , so can you please advise the script which will take ADM_ID as input from me
for example as per above feed file i can pass the ADM_ID as 861 from me , then that script will select all the rows where ADM_ID value is 861 (as rite now in the above sample there are
total 2 rows where ADM_ID value is 861) and then will put these two rows in the separate text file , so in this process a new file is created at the same location (/usr/cft/str)
and the name of the file is ADM_861 and this file will contain all the rows where ADM_ID value is 861 please advise the script for this, Thanks in advance :confused:

so finally the new file created by script at the same location named ADM_861 Wwill look like this..

0|0.00|24-Jun-14|SSRD|1677|82588|20-Mar-14|100004.00|0|Serest|TRRS|24-Mar-19||true|Receive|861|0|3862880
2|0.00|24-Dec-14|ESJD|1877|82885|20-Mar-14|100009.00|0|Serest|OPRS|24-Mar-19||true|Receive|861|0|3682880

Try:

awk -F\| '$(NF-2)==s{print > ("ADM_" s)}' s=861 file

or

awk -F\| '$(NF-2)==s' s=861 file > ADM_861

or

s=861; awk -F\| '$(NF-2)==s' s="$s" file > "ADM_$s"

Folks please advise can I save this command in a script file lets say named filesplitter.sh and set it's permission to 777 please advise so that last I will execute the file like sh filesplitter 861

Anything you can run at the command line (well, almost anything!) you can put in a script.

But I wouldn't set it's permissions to 777. With that you're inviting anyone to change the script. 755 is good enough, assuming you want anyone to be able to view or run the script.