Sed Grab everything before a comma [closed] - csv

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a csv file with the following headers and content:
Country,Fertility,Income
"United States","23,2","1222,21"
I am looking to grab everything before the comma in the Income column. So that I have the following output
Country,Fertility,Income
"United States","23,2","1222"

With sed:
sed 's/,[0-9]*"$/"/' file
Output:
Country,Fertility,Income
"United States","23,2","1222"
See: The Stack Overflow Regular Expressions FAQ

Related

how to find name john and replace with smith in Laravel from name column of a table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
My String from name Column
john_items.3
I want to fetch all these names that start with the john and replace all of them with smith and update columns like
**john_items.3**
will become
**smith_items.3**
$replacedItems = \App\Models\ModelName::where('name', 'LIKE','john'.'%' )
->get()
->map(function ($item) {
$item->name = str_replace('john', 'smith', $item->name);
$item->save();
return $item;
});
// Print all
dd($replacedItems->toArray());

convert date to timestamp in yii2? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
$date = Yii::$app->request->post('date');
$timestamp = strtotime($date);
var_dump($timestamp );
error
PHP Warning – yii\base\ErrorException
strtotime() expects parameter 1 to be string, array given
you should check you post for an array in $_POST('date')
in this case you could access at the value providing an index
$timestamp = strtotime($date[0]);

smarty url paramater that contains special character not getting in $smarty.get.otp [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am not able to get this otp parameter in smarty because it is ommiting + sign from url.
http://test.com/index.php?otp=+AU7Og==
I have used following code but not getting value +AU7Og== of otp parameter
{$smarty.get.otp|escape:html}
{$smarty.get.otp|escape:htmlall}
It's not a smarty problem. In the query of a URL, + represents a space. You'll have to encode the plus sign if you want to use it as part of a string parameter

transfer a simple text to json [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to convert a simple text to json programmatically using linux script bash or any other scripting language !
Raw text was like this :
Question 1 ?
Answer1,answer2,answer3{C},answer4
Question 2 ?
{C}Answer1,answer2,answer3,answer4
Question 3 ?
Answer1,answer2{C},answer3,answer4
...
Actually I succeeded to convert it , but now I need to update correct value to the right answer number tagged by {C} for every question !
{
"introduction":"My Quiz",
"questions":[
{"question":"Question 1?",
"answers":["answer1","answer2","answer3{C}","answer4"],
"correct":2},
{"question":"Question 2?",
"answers":["{C}answer1","answer2","answer3","answer4"],
"correct":2}
]
}
Any ideas ?
my ($correctans) = grep {s/.*(\d).*/$1/ if m/C/} (my #answers = qw({C}Answer1 answer2 answer3{C} answer4));

How to add to string a new string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a database with products.
I need to add to name of products some string.
Example:
product name "abc1", "abc2", "abc3"
new products name: "Super abc1", "Super abc2", "Super abc3"
Use MySQL's concat().
If you want to update :
update tablename set column=concat('Super ', column);
You can even add a where clause .
update player
set productName= concat("super ",productName)
You need to use CONCAT function
SELECT CONCAT('Super ',columnWithABc) from tab