LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2013, 06:18 PM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Rep: Reputation: 37
Question command to remove characters from a string


Hi All,

I'd like to create a script that would look into a file and remove characters from it.
For example:

file name: test

the file contains the following data: UPC/retail price

001234123820 $12.00
001245452814 $16.00
001234123373 $44.00
001234565532 $159.00

So I want to remove the first 4 characters of each line, the last character from the UPC code and the retail price including the dollar sign. (This is not a homework assignment, it is a painful process that I do at work but with many many more UPCs)

Thank you!!!
 
Old 10-23-2013, 06:59 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
many many ways to do it

the simplest being cut

Code:
cut -c 5-11 InputFile
when you re-word your question, you only want characters 5 to 11
 
Old 10-23-2013, 08:29 PM   #3
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Original Poster
Rep: Reputation: 37
Hi Fireat,

I know there are many ways. I kinda looked it up in google today; however, I got a little overwhelmed with the answers.

Would "cut -c 5-11 InputFile" remove the strings from every line in my file? Let's say about 20 or more lines.

and correct! I only want characters 5 to 11.

I will test this tomorrow at work.

Thank you
 
  


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
SED - remove last four characters from string 3saul Linux - Software 9 12-14-2015 05:43 PM
[SOLVED] Remove special characters from a string ajeesh.tr Programming 2 01-31-2011 01:12 AM
How to determine if a string contains some characters steven.c.banks Linux - General 4 08-27-2010 03:26 PM
Tcl: Remove all alphabetic characters at beginning of string BozMan Programming 3 07-27-2010 07:05 PM
bash command for removing special characters from string kkpal Linux - Newbie 5 05-26-2008 09:14 AM


All times are GMT -5. The time now is 12:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration