LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Linux User Groups (LUG)
User Name
Password
Linux User Groups (LUG) This forum allows Linux User Groups (LUG) to gain exposure. It also allows people looking for a LUG in their area to find one.

Notices


Reply
  Search this Thread
Old 03-27-2020, 12:10 AM   #1
nithylaa
LQ Newbie
 
Registered: Mar 2020
Posts: 3

Rep: Reputation: Disabled
Help me!! Urgent - Printing consecutive words


Hi,
Here is my requirement

Input
Text_1 Text_2 Text_3 Text_4 Text_5

Output
Text_2 Text_3 Text_4 Text_5
Text_1 Text_3 Text_4 Text_5
Text_1 Text_2 Text_4 Text_5
Text_1 Text_2 Text_3 Text_5
Text_1 Text_2 Text_3 Text_4

Can this be done in unix/linux scripting?

Last edited by nithylaa; 03-27-2020 at 12:12 AM. Reason: Typo changes
 
Old 03-27-2020, 12:22 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,773
Blog Entries: 3

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
Welcome to the forums.

Quote:
Originally Posted by nithylaa View Post
Hi,
Here is my requirement
And here are our requirements.

https://www.linuxquestions.org/linux...Ask_a_Question

This guide might help:

http://www.catb.org/~esr/faqs/smart-questions.html

Quote:
Originally Posted by nithylaa View Post
Can this be done in unix/linux scripting?
Yes, easily. But first there are some questions for you:

What specifically have you tried so far and where are you stuck?
Which distro is this on, including version?
Where is the data coming from, another program or a file?

Note, we do not do homework for you, you must do your school assignment youself. However, we can guide you through the tougher parts as you show work.

Last edited by Turbocapitalist; 03-27-2020 at 12:26 AM.
 
Old 03-27-2020, 03:00 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,336

Rep: Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626
Additionally: https://www.linuxquestions.org/linux/rules.html:
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an
LQ member.
Actually it can be solved using shell/grep/sed/awk/perl/python/whatever language you want. (so the answer is: YES) Which one do you prefer?
 
Old 03-27-2020, 03:44 AM   #4
nithylaa
LQ Newbie
 
Registered: Mar 2020
Posts: 3

Original Poster
Rep: Reputation: Disabled
I tried the following and used the gvim editor to perform modifications,

seq -s " " -f "Text_%02g" 1 5

But when I want to do for say 100 lines, its tough to do it. If I can do something with grep or sed it would be helpful.
 
Old 03-27-2020, 03:50 AM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,773
Blog Entries: 3

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
There are many ways to achieve the output given the input above, also with sed.

The place to start with sed scripting would be here:

https://www.grymoire.com/Unix/Sed.html

Learn a little of how sed is programed and then try some experiments.

Again, which distro do you have this on? And will the input come as output from another program directly or via a file?
 
Old 03-27-2020, 06:57 AM   #6
fatmac
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Posts: 3,539

Rep: Reputation: Disabled
As above the source of your info is quite important to know, as if it comes from another program, it could be piped through another to get the result you are after.
 
Old 03-27-2020, 10:45 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,336

Rep: Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626
I'm really sorry
Code:
i=0; _() { echo "$@"; }; __() { printf "%s " "$@"; }
IFS=" " read -r -a _l <<< "$(_ SGVscCBtZSBVcmdlbnQgUHJpbnRpbmcgY29uc2VjdXRpdmUgd29yZHMK | base64 -d)"
 while [[ ${_l[i]} ]]; do _1=("${_l[@]}"); unset '_1[$((i++))]'; __ \
"${_1[@]}"; _ ; done;
 
  


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
LXer: Words, Words, Words--Introducing OpenSearchServer LXer Syndicated Linux News 0 08-07-2019 02:13 PM
finding and removing duplicate consecutive words cocostaec Linux - Newbie 18 05-07-2011 01:25 PM
Removing white spaces between words and joining the words in a given format Priyabio Linux - General 4 08-20-2009 07:42 AM
How do I create words.db from words.txt using gdbm? kline General 8 12-14-2008 08:48 PM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 07:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Linux User Groups (LUG)

All times are GMT -5. The time now is 08:20 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