0

I have 100 ".txt" files. Each file contains the data such as

File name Data
1.txt     BAP1
2.txt     UCHL1
3.txt     ABC1234

Now I want to scan content of these files and write to txt file with condition that it contains my input string such as "BAP1". I used below coded but the output files have mistaken such as '1.txt .' I have no idea why the extension file has more dot in last file. Could you help me solve it? I am working in cygwin

#!/bin/sh
grep -w 'BAP1' *.txt>"1.txt"
grep -w 'UCHL1' *.txt>"2.txt"
Jame
  • 3,746
  • 6
  • 52
  • 101

1 Answers1

1

Run dos2unix on your script, or otherwise tell your editor to save it as a UNIX text file.

Otherwise, your filenames will have carriage returns (aka $'\r') on the end of their names.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441