Timeline for How can I select a record line from a file using SED
Current License: CC BY-SA 4.0
20 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 1, 2020 at 15:41 | vote | accept | user3490590 | ||
| Jul 1, 2020 at 15:37 | answer | added | AdminBee | timeline score: 0 | |
| Jul 1, 2020 at 15:32 | history | edited | user3490590 | CC BY-SA 4.0 |
added 209 characters in body
|
| Jul 1, 2020 at 15:32 | comment | added | AdminBee | If that's ok for you, I will post is as answer, then. | |
| Jul 1, 2020 at 15:30 | comment | added | user3490590 |
Thank you very much @AdminBee, [^[:print:]] worked! I appreciate other response as well, thanks for the help guys!
|
|
| Jul 1, 2020 at 14:50 | comment | added | AdminBee |
What happens if you include the space in the character list, as in grep '[^a-zA-Z0-9&,. -]'? These lines do, after all, contain spaces. BTW, if your grep and sed understand POSIX character classes, you may be able to use [^[:print:]] to match all "non-printable" characters ...
|
|
| Jul 1, 2020 at 14:46 | comment | added | user3490590 |
@AdminBee, tried the updated grep command grep '[^a-zA-Z0-9&,-]' however its getting all the lines.. :(
|
|
| Jul 1, 2020 at 14:19 | comment | added | AdminBee |
@user3490590 yeah sorry btw, did you notice I exchanged my comment? The grep line I originally posted and that you unfortunately used has a typo in it - the / ... / around the regular expression is wrong, please try the corrected one. As for the space: it would not matter in the replacement since you replace illegal characters with a space, so even if the space is considered illegal, the file de facto wouldn't change. For the "reporting" command however it does make a difference ...
|
|
| Jul 1, 2020 at 14:17 | comment | added | user3490590 |
Thanks for your responses.. Hi @AdminBee, tried grep '/[^a-zA-Z0-9&,-]/' > invalid_lines.txt, however it is not working :( no output on invalid_lines.txt, I am working on AS400 machine so I am not sure if its the platform... Do u have other solutions? Yes its fine to have two step approach or more than.. Regarding [space], i think I am good... the output from my sed -e 's/[^a-zA-Z0-9&,-]/ /g' uploadfile.txt > outputfile.txt command looks good to me...
|
|
| Jul 1, 2020 at 14:17 | answer | added | Alan Rezende | timeline score: 0 | |
| Jul 1, 2020 at 14:10 | comment | added | AdminBee |
Is a two-step approach viable, i.e. first do a grep '[^a-zA-Z0-9&,-]' > invalid_lines.txt, to print all lines with illegal characters to a file, and then perform your replacement sed call? Also, the "space" seems not to be on the list of allowed characters, are you sure there (it wouldn't matter in your purging command as you replace illegal characters with space, but it would for the "reporting" command)?
|
|
| Jul 1, 2020 at 13:48 | comment | added | Panki |
grep $character uploadfile.txt, replace $character with the value of the control character (probably \x1C).
|
|
| Jul 1, 2020 at 13:42 | comment | added | user3490590 | Hello, I'm sorry... The post has been edited. I am open for any solution and will try to integrate it to my program, hopefully it will work to my platform. Thanks again. | |
| Jul 1, 2020 at 13:39 | history | edited | user3490590 | CC BY-SA 4.0 |
added 390 characters in body
|
| Jul 1, 2020 at 12:26 | review | Close votes | |||
| Jul 17, 2020 at 3:08 | |||||
| Jul 1, 2020 at 10:52 | comment | added | AdminBee |
Can you edit your post to provide (possibly anonymized) sample input together with corresponding desired output? As stated by @seshoumara, your grep call may not produce error messages, but certainly does not do what you intend it to do (notice that in addition, the . is not mentioned in your RegExp). Also, are you interested in any solution (including fixing the grep call) or does it need to be a sed-based solution?
|
|
| Jul 1, 2020 at 10:36 | history | edited | AdminBee | CC BY-SA 4.0 |
Added verbatim code formatting for code parts, "CAPS"->"uppercase", "small caps"->"lowercase"
|
| Jul 1, 2020 at 8:58 | comment | added | seshoumara | I don't understand how that grep command is supposed to do what you want. It looks to me more that it actually searches for the lines containing those characters followed by 'p' and printing also the line numbers of the lines that matched. | |
| Jul 1, 2020 at 8:35 | review | First posts | |||
| Jul 1, 2020 at 10:37 | |||||
| Jul 1, 2020 at 8:28 | history | asked | user3490590 | CC BY-SA 4.0 |