ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi I would like to remove part of a word but with cut i cannot put no space for the delim
Code:
cat /home/xxx/Desktop/xxx/file |grep lin|cut -d " " -f 1|cut -d"" -f 1
cut: the delimiter must be a single character
Try `cut --help' for more information.
what i am trying in the above code is for example "I search for the word linux0001 but i only want the middle character "ux0"
Are you saying you just want the first 3 characters after anything that contains "lin"?
If that is all you need:
sed d -n 's/.*\lin\(...\).*/\1/p' /home/xxx/Desktop/xxx/file
Beware, you probably want to be more specific, so that things like /usr/linux/foo does not match. Clarify as much as you can the pattern that is necessary to correctly determine your needs.
ok what i am trying to do is from the word usa12312301 which in my case means usa is country and 123123 is branch and 01 wkst i just want the branch number...so far i have managed to get an output of the numbers only 12312301 but now i want to take out the last two numbers 01 so that i end up with just the branch num 123123
You want to use regular expressions here if the parts of your string vary in length. If they are all fixed length, or have clear delimiters, you can use cut or other tools for cutting operations.
So, are you branches always 6 digits, and branch numbers 2 digits?
last thing the problem i am getting now is that it cuts the character correctly but only on the first string .... usa12312301 after running echo usa12312301|cut -c4-9 i get 123123 but my file has many strings usa12312301 usa12355502 usa1236673 now it only displays the first one sting 123123 i want the cmd to work on each sting in a file and echo all
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.