Skip to main content
added 209 characters in body
Source Link

Apologies... Code that I shared earlier is incorrect, revising...

Revised Question:

First of all, I would like to apologize for the rush, I am new in QSHELL and just started learning.. But I badly need your help as I need to integrate the following to my program as soon as possible..

Basically the scenario is, a text file containing invalid/special characters was uploaded into our server and my program must remove them before processing.

so for example, I have uploadfile.txt and it contains below.

enter image description here

To replace the special characters I am using the following command and it works fine.

sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. & Ampersand
  5. , Comma
  6. . Period

However, before replacing I need to extract the lines for reporting/communication purposes and I am not quite sure how and got stuck... Tried to search however I still cant get it and I am running out of time..

So my question is, How can I extract line numbers 2, 4, 5 into a separate text.file?

Thanks in advance.

This has been resolved, I used below command as suggested by @adminbee in the comments.

sed -n '/[^[:print:]]/p' IFS/MM4R5FLR/S06013/myfile.POL > myfile.pol
Thank you everyone for the help.

Apologies... Code that I shared earlier is incorrect, revising...

Revised Question:

First of all, I would like to apologize for the rush, I am new in QSHELL and just started learning.. But I badly need your help as I need to integrate the following to my program as soon as possible..

Basically the scenario is, a text file containing invalid/special characters was uploaded into our server and my program must remove them before processing.

so for example, I have uploadfile.txt and it contains below.

enter image description here

To replace the special characters I am using the following command and it works fine.

sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. & Ampersand
  5. , Comma
  6. . Period

However, before replacing I need to extract the lines for reporting/communication purposes and I am not quite sure how and got stuck... Tried to search however I still cant get it and I am running out of time..

So my question is, How can I extract line numbers 2, 4, 5 into a separate text.file?

Thanks in advance.

Apologies... Code that I shared earlier is incorrect, revising...

Revised Question:

First of all, I would like to apologize for the rush, I am new in QSHELL and just started learning.. But I badly need your help as I need to integrate the following to my program as soon as possible..

Basically the scenario is, a text file containing invalid/special characters was uploaded into our server and my program must remove them before processing.

so for example, I have uploadfile.txt and it contains below.

enter image description here

To replace the special characters I am using the following command and it works fine.

sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. & Ampersand
  5. , Comma
  6. . Period

However, before replacing I need to extract the lines for reporting/communication purposes and I am not quite sure how and got stuck... Tried to search however I still cant get it and I am running out of time..

So my question is, How can I extract line numbers 2, 4, 5 into a separate text.file?

Thanks in advance.

This has been resolved, I used below command as suggested by @adminbee in the comments.

sed -n '/[^[:print:]]/p' IFS/MM4R5FLR/S06013/myfile.POL > myfile.pol
Thank you everyone for the help.

added 390 characters in body
Source Link

I am a noob programmer and trying to convert below GREP code to SED.Apologies... Code that I shared earlier is incorrect, revising...

grep -ne '[a-zA-Z0-9&,-]p' 'myfile.txt' > 'myfile2.txt'

Revised Question:

HoweverFirst of all, I am not quite sure how sincewould like to apologize for the rush, I am not familiar with qshell commandsnew in QSHELL and just started studyinglearning. I. But I badly need your help sinceas I haveneed to integrate the codefollowing to my program as soon as possible..

Basically what I am trying to dothe scenario is - I want to extract lines that are not, a text file containing invalid/special characters was uploaded into our server and my program must remove them before processing.

so for example, I have uploadfile.txt and it contains below.

enter image description here

To replace the special characters I am using the following: command and it works fine.

sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt

  1. a to to z lowercase (a-za-z)
  2. A to to Z uppercase (A-ZA-Z)
  3. 0-9
  4. Ampersand (&) Ampersand
  5. Comma (,) Comma
  6. Period (.) Period

Above grep file works however upon extracting myfile2.txt it contains unreadableHowever, before replacing I need to extract the lines for reporting/special characterscommunication purposes and I am not quite sure how and got stuck. Tried below SED.. Tried to search however I still cant get it does not workand I am running out of time..

sed -n '/[a-zA-Z0-9&,-]/' IFS/MM4R5FLR/S06013/LAWPOLaa.POL  

So my question is, How can I extract line numbers 2, 4, 5 into a separate text.file?

Thanks in advance.

I am a noob programmer and trying to convert below GREP code to SED.

grep -ne '[a-zA-Z0-9&,-]p' 'myfile.txt' > 'myfile2.txt'

However I am not quite sure how since I am not familiar with qshell commands and just started studying. I badly need your help since I have to integrate the code to my program as soon as possible.

Basically what I am trying to do is - I want to extract lines that are not containing the following:

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. Ampersand (&)
  5. Comma (,)
  6. Period (.)

Above grep file works however upon extracting myfile2.txt it contains unreadable/special characters. Tried below SED however it does not work.

sed -n '/[a-zA-Z0-9&,-]/' IFS/MM4R5FLR/S06013/LAWPOLaa.POL  

Thanks in advance.

Apologies... Code that I shared earlier is incorrect, revising...

Revised Question:

First of all, I would like to apologize for the rush, I am new in QSHELL and just started learning.. But I badly need your help as I need to integrate the following to my program as soon as possible..

Basically the scenario is, a text file containing invalid/special characters was uploaded into our server and my program must remove them before processing.

so for example, I have uploadfile.txt and it contains below.

enter image description here

To replace the special characters I am using the following command and it works fine.

sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. & Ampersand
  5. , Comma
  6. . Period

However, before replacing I need to extract the lines for reporting/communication purposes and I am not quite sure how and got stuck... Tried to search however I still cant get it and I am running out of time..

So my question is, How can I extract line numbers 2, 4, 5 into a separate text.file?

Thanks in advance.

Added verbatim code formatting for code parts, "CAPS"->"uppercase", "small caps"->"lowercase"
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

I am a noob programmer and trying to convert below GREP code to SED.

grep -ne '[a-zA-Z0-9&,-]p' 'myfile.txt' > 'myfile2.txt'

However I am not quite sure how since I am not familiar with qshell commands and just started studying. I badly need your help since I have to integrate the code to my program as soon as possible.

Basically what I am trying to do is - I want to extract lines that are not containing the following:

  1. aa to z small caps z lowercase (a-za-z)
  2. AA to Z CAPSZ uppercase (A-ZA-Z)
  3. 0-90-9
  4. Ampersand (&&)
  5. Comma (,,)
  6. Period (..)

Above grepgrep file works however upon extracting myfile2.txtmyfile2.txt it contains unreadable/special characters. Tried below SED however it does not work.

sed -n '/[a-zA-Z0-9&,-]/' IFS/MM4R5FLR/S06013/LAWPOLaa.POL  

Thanks in advance.

I am a noob programmer and trying to convert below GREP code to SED.

grep -ne '[a-zA-Z0-9&,-]p' 'myfile.txt' > 'myfile2.txt'

However I am not quite sure how since I am not familiar with qshell commands and just started studying. I badly need your help since I have to integrate the code to my program as soon as possible.

Basically what I am trying to do is - I want to extract lines that are not containing the following:

  1. a to z small caps (a-z)
  2. A to Z CAPS (A-Z)
  3. 0-9
  4. Ampersand (&)
  5. Comma (,)
  6. Period (.)

Above grep file works however upon extracting myfile2.txt it contains unreadable/special characters. Tried below SED however it does not work.

sed -n '/[a-zA-Z0-9&,-]/' IFS/MM4R5FLR/S06013/LAWPOLaa.POL  

Thanks in advance.

I am a noob programmer and trying to convert below GREP code to SED.

grep -ne '[a-zA-Z0-9&,-]p' 'myfile.txt' > 'myfile2.txt'

However I am not quite sure how since I am not familiar with qshell commands and just started studying. I badly need your help since I have to integrate the code to my program as soon as possible.

Basically what I am trying to do is - I want to extract lines that are not containing the following:

  1. a to z lowercase (a-z)
  2. A to Z uppercase (A-Z)
  3. 0-9
  4. Ampersand (&)
  5. Comma (,)
  6. Period (.)

Above grep file works however upon extracting myfile2.txt it contains unreadable/special characters. Tried below SED however it does not work.

sed -n '/[a-zA-Z0-9&,-]/' IFS/MM4R5FLR/S06013/LAWPOLaa.POL  

Thanks in advance.

Source Link
Loading