LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   printing a character to file (https://www.linuxquestions.org/questions/linux-newbie-8/printing-a-character-to-file-747578/)

catkin 08-15-2009 06:41 AM

Quote:

Originally Posted by Completely Clueless (Post 3644176)
Okay, thanks for the clarification, Charles. However, as I stated earlier in this thread......

"I reckon C is far more suited to this particular task, so I'm going to switch at this point. Thanks for all the ideas anyway, guys."

Your almost certainly right (not knowing what this particular task is, I can't be sure but C is way faster than shell) but I didn't want you to change from bash to C because you thought bash could not do it.

Completely Clueless 08-15-2009 07:31 AM

Quote:

Originally Posted by catkin (Post 3644258)
Your almost certainly right (not knowing what this particular task is, I can't be sure but C is way faster than shell) but I didn't want you to change from bash to C because you thought bash could not do it.

That's fine, Charles. I'm sure Bash could do it, but it's more of a C job IMHO. I'm increasingly aware of the strengths and weaknesses of Bash, will continue to learn it and respect it for what it does well. At the same time, I'm going to dust off my rusty old C coding experience and polish up on that, too.

Pushing 90 degrees here again today I'm sorry to say. Now where did I put those salt tablets?

MensaWater 08-15-2009 09:02 AM

If you like C and want to do scripting very similar to it you might want to investigate Perl.

Completely Clueless 08-15-2009 10:27 AM

Quote:

Originally Posted by jlightner (Post 3644364)
If you like C and want to do scripting very similar to it you might want to investigate Perl.

Sorry, you'll have to excuse my ignorance, but what advantage would that confer?

catkin 08-15-2009 10:56 AM

Quote:

Originally Posted by Completely Clueless (Post 3644417)
Sorry, you'll have to excuse my ignorance, but what advantage would that confer?

Familiarising oneself with 3 languages at the same time has great confusion potential++

Completely Clueless 08-15-2009 11:08 AM

Quote:

Originally Posted by catkin (Post 3644442)
Familiarising oneself with 3 languages at the same time has great confusion potential++

Too true, Charles! That's why I am determined to strenuously avoid the psuedo-C constructs that Bash can parse. The syntax isn't *quite* the same, which certainly could cause problems for me in both.

catkin 08-15-2009 01:35 PM

Quote:

Originally Posted by Completely Clueless (Post 3644454)
Too true, Charles! That's why I am determined to strenuously avoid the pseudo-C constructs that Bash can parse. The syntax isn't *quite* the same, which certainly could cause problems for me in both.

Which would make PERL an ideal choice to maximise confusion; it looks like a mixture of shellscript and C with its own pathologically eclectic rubbish thrown in for good measure.

w1k0 08-15-2009 04:52 PM

Quote:

Originally Posted by catkin (Post 3643672)
What's the problem?

The problem is your script removes new lines characters. To avoid it you have to change delimiter:

Code:

#!/bin/sh

> outfile.txt

while read -n1 -d "^["
do
    echo -n "$REPLY" >> outfile.txt
done < infile.txt


w1k0 08-16-2009 11:10 AM

"^[" in the above script doesn't mean two characters: ^ and [ but one character: escape. To get it you could use vim. It's enough to go to editing mode, to press Ctrl-V for literal mode, and to press Esc for escape character.

If you're not acquainted with vim try that sequence:

Open the script with the command: vim your_script_name.
Go to the desired position using arrows.
Press i (lowercase i) for insert mode.
Press Ctrl-V (Ctrl and v) for literal mode.
Press Esc for escape character.
Press Esc to exit editing mode.
Press ZZ (uppercase Z twice) to save changes and exit vim.


All times are GMT -5. The time now is 03:02 PM.