LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2004, 03:18 PM   #1
Xa!
LQ Newbie
 
Registered: Mar 2004
Location: .ru/moscow
Distribution: Gentoo
Posts: 17

Rep: Reputation: 0
Change first char of each line in a file to '0' using /bin/sh


Hello!

I have a file, and I want to write a script, that changes _first_ char of _every_ line of this file to '0'.

Let i have file.txt
--------------
1 1 0 0 1 0 0
0 1 1 0 0 0 0
1 1 1 1 1 1 1
1 1 1 1 1 1 1
--------------
and i want
--------------
0 1 0 0 1 0 0
0 1 1 0 0 0 0
0 1 1 1 1 1 1
0 1 1 1 1 1 1
--------------

I think it could be done with sed -e s/{hm.. what to write here?}/0/ < file.txt, but how?
 
Old 10-25-2004, 03:48 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
#!/bin/sh

sed -e 's/^./0/' file.txt
 
Old 12-12-2010, 10:00 PM   #3
DearWebby
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Rep: Reputation: 0
Quote:
Originally Posted by Hko View Post
Code:
#!/bin/sh

sed -e 's/^./0/' file.txt

Can I use something like that to cut the first n characters from each line?
 
Old 12-12-2010, 10:05 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by DearWebby View Post
Can I use something like that to cut the first n characters from each line?
That should have been covered in your class sessions or other course resources. LQ is here to help people when they get stuck, not to do people's homework. What have you tried so far?

EDIT:

BTW, if you changed the first character of every line the output would be (in CODE tags so it lines up nicely):
Code:
0-------------
0 1 0 0 1 0 0
0 1 1 0 0 0 0
0 1 1 1 1 1 1
0 1 1 1 1 1 1
0-------------
EDIT2:

Have you learned how to search the online manual database (the man pages) by keywords? Try man -k cut to get a list of commands about cutting. The manual section 1 commands are the most relevant for introductory scripting. You can restrict the list to those with man -k cut | grep '(1)'. When you want to know more about a listed command you can view its man page with, for example, man cut

Last edited by catkin; 12-12-2010 at 10:14 PM.
 
Old 12-12-2010, 11:51 PM   #5
DearWebby
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Rep: Reputation: 0
I am not privileged enough to be able to attend classes or courses. What I know is from studying helpful answers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sh: line 1: /usr/bin/(swapd): No such file or directory QtCoder Linux - General 4 04-11-2005 05:33 PM
BASH: How to change a line in file? gmitra Programming 4 01-28-2005 07:26 AM
What does this mean? suSE9.1 ATI "/bin/sh: line 1: scripts/modpost: No such file or" op_stager Linux - Hardware 0 09-29-2004 11:28 PM
Error in man command "sh: line 1: /usr/bin/gtbl: No such file or directory" MinA Slackware 1 09-06-2004 06:36 PM
Change /bin/bash to /bin/zsh Smokey Slackware 12 07-14-2004 01:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration